Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Rustom Mody
On Tuesday, December 5, 2017 at 12:40:01 AM UTC+5:30, Jason Maldonis wrote: > I was extending a `list` and am wondering why slicing lists will never > raise an IndexError, even if the `slice.stop` value if greater than the > list length. > > Quick example: > > my_list = [1, 2, 3] > my_list[:100]

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Rick Johnson
Ned Batchelder wrote: [...] > The point of the example was to demonstrate what happens > when slicing beyond the bounds of the list. It's beyond > the scope of the thread to debate whether you might want to > perform an action in that case. But, nevertheless, the else-clause is there! And th

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Ned Batchelder
On 12/4/17 9:31 PM, Rick Johnson wrote: On Monday, December 4, 2017 at 7:47:20 PM UTC-6, Ned Batchelder wrote: [...] Here are details filled in: $ python3.6 Python 3.6.3 (default, Oct 4 2017, 06:03:25) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Chris Angelico
On Tue, Dec 5, 2017 at 1:31 PM, Rick Johnson wrote: > On Monday, December 4, 2017 at 7:47:20 PM UTC-6, Ned Batchelder wrote: > > [...] > >> Here are details filled in: >> >> $ python3.6 >> Python 3.6.3 (default, Oct 4 2017, 06:03:25) >> [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-90

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Rick Johnson
On Monday, December 4, 2017 at 7:47:20 PM UTC-6, Ned Batchelder wrote: [...] > Here are details filled in: > > $ python3.6 > Python 3.6.3 (default, Oct 4 2017, 06:03:25) > [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin > Type "help", "copyright", "credits

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread MRAB
On 2017-12-05 01:37, Jason Maldonis wrote: [snip] So I guess the conclusion (as far as I can tell) is that: `my_string[:n]` is more convenient than `my_string[:min(n, len(my_string))]`, and that sounds okay enough to me. If I'm being completely honest I kinda like the logical explicitness of t

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Ned Batchelder
On 12/4/17 8:03 PM, Rick Johnson wrote: On Monday, December 4, 2017 at 6:13:19 PM UTC-6, Chris Angelico wrote: [...] Ahhh, I see how it is. You didn't run the code, ergo you don't understand it. Makes perfect sense. :) Being that Terry didn't offer any declarations or defintions for his

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Jason Maldonis
I'll try to summarize what I've learned with a few responses in hodge-podge order and to no one in particular: >That's a feature dude, not a bug. Absolutely. I _do not_ think that how slicing works in python should be changed, but I _do_ want to understand its design decisions because it will mak

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Rick Johnson
On Monday, December 4, 2017 at 6:13:19 PM UTC-6, Chris Angelico wrote: [...] > Ahhh, I see how it is. You didn't run the code, ergo you > don't understand it. Makes perfect sense. :) Being that Terry didn't offer any declarations or defintions for his variables or functions, i assumed,

Re: zlib OverflowError: 'size does not fit in an int'

2017-12-04 Thread Larry Martell
On Mon, Dec 4, 2017 at 7:36 PM, Thomas Jollans wrote: > On 05/12/17 01:21, Larry Martell wrote: >> On Mon, Dec 4, 2017 at 7:15 PM, Chris Angelico wrote: >>> On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell >>> wrote: Trying to zip a large file is failing with OverflowError: 'size does n

Re: zlib OverflowError: 'size does not fit in an int'

2017-12-04 Thread Thomas Jollans
On 05/12/17 01:21, Larry Martell wrote: > On Mon, Dec 4, 2017 at 7:15 PM, Chris Angelico wrote: >> On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell >> wrote: >>> Trying to zip a large file is failing with OverflowError: 'size does >>> not fit in an int'. Googling I found this: >>> >>> https://bugs

Re: zlib OverflowError: 'size does not fit in an int'

2017-12-04 Thread Thomas Jollans
On 05/12/17 01:15, Chris Angelico wrote: > On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell > wrote: >> Trying to zip a large file is failing with OverflowError: 'size does >> not fit in an int'. Googling I found this: >> >> https://bugs.python.org/issue23306 >> >> and this: >> >> https://hg.python

Re: zlib OverflowError: 'size does not fit in an int'

2017-12-04 Thread Larry Martell
On Mon, Dec 4, 2017 at 7:15 PM, Chris Angelico wrote: > On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell > wrote: >> Trying to zip a large file is failing with OverflowError: 'size does >> not fit in an int'. Googling I found this: >> >> https://bugs.python.org/issue23306 >> >> and this: >> >> htt

Re: Please tell me how to execute python file in Ubuntu by double clicking on file.

2017-12-04 Thread Thomas Jollans
On 05/12/17 01:03, Michael Torrie wrote: > On 12/04/2017 04:49 AM, Thomas Jollans wrote: >> On 2017-12-04 10:48, dhananjaysingh091...@gmail.com wrote: >>> Respected Sir/Mam, >>> I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am >>> double click in python program (Dhananjay.py

Re: zlib OverflowError: 'size does not fit in an int'

2017-12-04 Thread Chris Angelico
On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell wrote: > Trying to zip a large file is failing with OverflowError: 'size does > not fit in an int'. Googling I found this: > > https://bugs.python.org/issue23306 > > and this: > > https://hg.python.org/cpython/rev/2192edcfea02 > > which seems to make

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Chris Angelico
On Tue, Dec 5, 2017 at 10:50 AM, Rick Johnson wrote: > Chris Angelico wrote: >> wrote: >> > Terry Reedy wrote: >> > >> > [...] >> > >> >> try: >> >> item = seq[n] >> >> except IndexError >> >> do_without_item() >> >> else: >> >> process(item) >> >> >> >> item = seq[n:n+1] >> >> if

Re: Please tell me how to execute python file in Ubuntu by double clicking on file.

2017-12-04 Thread Michael Torrie
On 12/04/2017 04:49 AM, Thomas Jollans wrote: > On 2017-12-04 10:48, dhananjaysingh091...@gmail.com wrote: >> Respected Sir/Mam, >> I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am >> double click in python program (Dhananjay.py),it is opening in Text Editor >> by Default i

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Rick Johnson
Chris Angelico wrote: > wrote: > > Terry Reedy wrote: > > > > [...] > > > >> try: > >> item = seq[n] > >> except IndexError > >> do_without_item() > >> else: > >> process(item) > >> > >> item = seq[n:n+1] > >> if item: > >> process(item) > >> else: > >> do_without_item() >

zlib OverflowError: 'size does not fit in an int'

2017-12-04 Thread Larry Martell
Trying to zip a large file is failing with OverflowError: 'size does not fit in an int'. Googling I found this: https://bugs.python.org/issue23306 and this: https://hg.python.org/cpython/rev/2192edcfea02 which seems to make me think this was fixed this was fixed on Jul 23 2016. I am running Ce

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Cameron Simpson
On 04Dec2017 14:13, Jason Maldonis wrote: And I'll be honest -- I like the implementation of the LazyList I wrote above. I think it's pretty logical, because it allows you to think about the lazy list like this: "Treat the list like a norma list. If you run out of bounds, get more data, then tr

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Chris Angelico
Against my better judgement, I'm going to ask... On Tue, Dec 5, 2017 at 9:22 AM, Rick Johnson wrote: > Terry Reedy wrote: > > [...] > >> try: >> item = seq[n] >> except IndexError >> do_without_item() >> else: >> process(item) >> >> item = seq[n:n+1] >> if item: >> process(ite

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Rick Johnson
Terry Reedy wrote: [...] > try: > item = seq[n] > except IndexError > do_without_item() > else: > process(item) > > item = seq[n:n+1] > if item: > process(item) > else: > do_without_item() > > Many prefer the second. And they'll prefer it even more when they real

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Terry Reedy
On 12/4/2017 1:54 PM, Jason Maldonis wrote: I was extending a `list` and am wondering why slicing lists will never raise an IndexError, even if the `slice.stop` value if greater than the list length. Is there any background on why that doesn't raise an IndexError? Slicing is perhaps most com

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread MRAB
On 2017-12-04 21:22, Jason Maldonis wrote: >> This is explained in the Python tutorial for strings >> https://docs.python.org/3/tutorial/introduction.html#strings, as a list >> is a sequence just like a string it will act in exactly the same way. >> > > The only relevant bit I found in that link

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Rick Johnson
On Monday, December 4, 2017 at 1:10:01 PM UTC-6, Jason Maldonis wrote: > I was extending a `list` and am wondering why slicing lists will never > raise an IndexError, even if the `slice.stop` value if greater than the > list length. > > Quick example: > > my_list = [1, 2, 3] > my_list[:100] # does

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Paul Moore
On 4 December 2017 at 20:13, Jason Maldonis wrote: > And I'll be honest -- I like the implementation of the LazyList I wrote > above. I think it's pretty logical, because it allows you to think about > the lazy list like this: "Treat the list like a norma list. If you run out > of bounds, get mor

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Jason Maldonis
> > >> This is explained in the Python tutorial for strings > >> https://docs.python.org/3/tutorial/introduction.html#strings, as a list > >> is a sequence just like a string it will act in exactly the same way. > >> > > > > The only relevant bit I found in that link is: "However, out of range > >

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Chris Angelico
On Tue, Dec 5, 2017 at 8:03 AM, Jason Maldonis wrote: >> >> This is explained in the Python tutorial for strings >> https://docs.python.org/3/tutorial/introduction.html#strings, as a list >> is a sequence just like a string it will act in exactly the same way. >> > > The only relevant bit I found

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Jason Maldonis
> > This is explained in the Python tutorial for strings > https://docs.python.org/3/tutorial/introduction.html#strings, as a list > is a sequence just like a string it will act in exactly the same way. > The only relevant bit I found in that link is: "However, out of range slice indexes are hand

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread breamoreboy
On Monday, December 4, 2017 at 7:10:01 PM UTC, Jason Maldonis wrote: > I was extending a `list` and am wondering why slicing lists will never > raise an IndexError, even if the `slice.stop` value if greater than the > list length. > > Quick example: > > my_list = [1, 2, 3] > my_list[:100] # does

Re: Python installer hangs in Windows 7

2017-12-04 Thread christian . gabrisch
Same with me, except that I tried to install Python 3.6.3. Unchecking "Install launcher for all users" helped, however. -- https://mail.python.org/mailman/listinfo/python-list

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Jason Maldonis
>Why would this simplify your code? What are you doing that would benefit >from an IndexError here? Without simplifying too much, I'm writing a wrapper around a REST API. I want lazy-loading functionality for lists-of-things, so I am creating a LazyList class. This LazyList class will load items

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Jason Maldonis
> > Have you ever used a language that does that? I have. > The String class in the C# language does that, and it's /really/ annoying. > I have to add extra code to prevent such exceptions. > In practice, I find that the way that Python does it is much nicer. (And > Python isn't unique in this res

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread MRAB
On 2017-12-04 18:54, Jason Maldonis wrote: I was extending a `list` and am wondering why slicing lists will never raise an IndexError, even if the `slice.stop` value if greater than the list length. Quick example: my_list = [1, 2, 3] my_list[:100] # does not raise an IndexError, but instead re

Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Random832
On Mon, Dec 4, 2017, at 13:54, Jason Maldonis wrote: > Is there any background on why that doesn't raise an IndexError? Knowing > that might help me design my extended list class better. For my specific > use case, it would simplify my code (and prevent `if isinstance(item, > slice)` checks) if the

Re: How to use a regexp here

2017-12-04 Thread Cecil Westerhof
Neil Cerutti writes: > On 2017-12-04, Cecil Westerhof wrote: >> Joel Goldstick writes: >> >>> On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder >>> wrote: >>> On 12/4/17 4:36 AM, Cecil Westerhof wrote: > I have a script that was running perfectly for some time. It uses: > a

Re: How to use a regexp here

2017-12-04 Thread Cecil Westerhof
Rick Johnson writes: >> There is now also a line that starts with: PCH_CPU_TEMP: >> And I do not want that one. > > Yes. But be aware, that while the `str.startswith(target)` > method is indeed more efficient than a more generalized > "inclusion test", if the target is not _always_ at the > begin

why won't slicing lists raise IndexError?

2017-12-04 Thread Jason Maldonis
I was extending a `list` and am wondering why slicing lists will never raise an IndexError, even if the `slice.stop` value if greater than the list length. Quick example: my_list = [1, 2, 3] my_list[:100] # does not raise an IndexError, but instead returns the full list Is there any background

Re: How to use a regexp here

2017-12-04 Thread Neil Cerutti
On 2017-12-04, Cecil Westerhof wrote: > Joel Goldstick writes: > >> On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder >> wrote: >> >>> On 12/4/17 4:36 AM, Cecil Westerhof wrote: >>> I have a script that was running perfectly for some time. It uses: array = [elem for elem in output if

Re: How to use a regexp here

2017-12-04 Thread Terry Reedy
On 12/4/2017 11:14 AM, Ned Batchelder wrote: On 12/4/17 9:13 AM, Rick Johnson wrote: Perhaps it's not politically correct for me to say this, but i've never been one who cared much about political correctness, so i'm just going to say it... Cecil, feel free to ignore the rest of Rick's message

Re: How to use a regexp here

2017-12-04 Thread Ned Batchelder
On 12/4/17 9:13 AM, Rick Johnson wrote: Perhaps it's not politically correct for me to say this, but i've never been one who cared much about political correctness, so i'm just going to say it... Cecil, feel free to ignore the rest of Rick's message.  His messages are famous for their outrageo

Re: Please tell me how to execute python file in Ubuntu by double clicking on file.

2017-12-04 Thread Rick Johnson
On Monday, December 4, 2017 at 3:49:11 AM UTC-6, dhananjays...@gmail.com wrote: > I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when > i am double click in python program (Dhananjay.py),it is > opening in Text Editor by Default in Ubuntu.I want to run > this program when i double click on i

Re: How to use a regexp here

2017-12-04 Thread Rick Johnson
Cecil Westerhof wrote: > Joel Goldstick writes: [...] > > I like Ned's clear answer, but I'm wondering why the > > original code would fail because the substring is at the > > start of the line, since 'in' would still be true no > > matter where the desired string is placed. It would be > >

Re: How to use a regexp here

2017-12-04 Thread Cecil Westerhof
Joel Goldstick writes: > On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder > wrote: > >> On 12/4/17 4:36 AM, Cecil Westerhof wrote: >> >>> I have a script that was running perfectly for some time. It uses: >>> array = [elem for elem in output if 'CPU_TEMP' in elem] >>> >>> But because output h

Re: How to use a regexp here

2017-12-04 Thread Cecil Westerhof
Ned Batchelder writes: > On 12/4/17 4:36 AM, Cecil Westerhof wrote: >> I have a script that was running perfectly for some time. It uses: >> array = [elem for elem in output if 'CPU_TEMP' in elem] >> >> But because output has changed, I have to check for CPU_TEMP at the >> beginning of the l

Re: Please tell me how to execute python file in Ubuntu by double clicking on file.

2017-12-04 Thread Thomas Jollans
On 2017-12-04 10:48, dhananjaysingh091...@gmail.com wrote: > Respected Sir/Mam, > I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am > double click in python program (Dhananjay.py),it is opening in Text Editor by > Default in Ubuntu.I want to run this program when i double cl

Re: How to use a regexp here

2017-12-04 Thread Joel Goldstick
On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder wrote: > On 12/4/17 4:36 AM, Cecil Westerhof wrote: > >> I have a script that was running perfectly for some time. It uses: >> array = [elem for elem in output if 'CPU_TEMP' in elem] >> >> But because output has changed, I have to check for CPU_

Re: How to use a regexp here

2017-12-04 Thread Ned Batchelder
On 12/4/17 4:36 AM, Cecil Westerhof wrote: I have a script that was running perfectly for some time. It uses: array = [elem for elem in output if 'CPU_TEMP' in elem] But because output has changed, I have to check for CPU_TEMP at the beginning of the line. What would be the best way to impl

Re: How to use a regexp here

2017-12-04 Thread breamoreboy
On Monday, December 4, 2017 at 9:44:27 AM UTC, Cecil Westerhof wrote: > I have a script that was running perfectly for some time. It uses: > array = [elem for elem in output if 'CPU_TEMP' in elem] > > But because output has changed, I have to check for CPU_TEMP at the > beginning of the line.

Please tell me how to execute python file in Ubuntu by double clicking on file.

2017-12-04 Thread dhananjaysingh091298
Respected Sir/Mam, I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am double click in python program (Dhananjay.py),it is opening in Text Editor by Default in Ubuntu.I want to run this program when i double click on it as any *.Exe file executes as in Window. Sir please help

Blog for basic python programming

2017-12-04 Thread manishti2004
Python for Engineers - Solve Problems by Coding Solutions https://pythonforengineers.blogspot.in -- https://mail.python.org/mailman/listinfo/python-list

How to use a regexp here

2017-12-04 Thread Cecil Westerhof
I have a script that was running perfectly for some time. It uses: array = [elem for elem in output if 'CPU_TEMP' in elem] But because output has changed, I have to check for CPU_TEMP at the beginning of the line. What would be the best way to implement this? -- Cecil Westerhof Senior Softwa