Re: Is this a "gotcha" in Python?

2019-04-22 Thread Chris Angelico
On Tue, Apr 23, 2019 at 8:41 AM Skip Montanaro wrote: >> >> By "accepted" you mean that it isn't complaining? > > Accepted, as in it provokes no complaints. > >> What kind of flagging? > > Unused. > Cool, thanks. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Is this a "gotcha" in Python?

2019-04-22 Thread Skip Montanaro
> > By "accepted" you mean that it isn't complaining? Accepted, as in it provokes no complaints. What kind of flagging? Unused. S -- https://mail.python.org/mailman/listinfo/python-list

Re: Is this a "gotcha" in Python?

2019-04-22 Thread Chris Angelico
On Tue, Apr 23, 2019 at 8:21 AM Skip Montanaro wrote: > > > Interesting. So it would flag this code? > > > > for _ in range(5): next(f) # skip five lines > > As of at least recent versions (I have 2.1.1 in my Conda install at > home) It seems to properly accept "_" as a variable name, even when >

Re: Is this a "gotcha" in Python?

2019-04-22 Thread Skip Montanaro
> Interesting. So it would flag this code? > > for _ in range(5): next(f) # skip five lines As of at least recent versions (I have 2.1.1 in my Conda install at home) It seems to properly accept "_" as a variable name, even when not used. It also seems to accept any variable name as a loop index. H

Re: Is this a "gotcha" in Python?

2019-04-22 Thread Chris Angelico
On Tue, Apr 23, 2019 at 7:28 AM Skip Montanaro wrote: > > > Not quite. The single-letter names mean "I am an iterator/index/etc", > > but "_" means "I am not used anywhere". > > Small addendum to this. pyflakes (at least in my experience) doesn't > interpret "_" as a variable name or prefix to a l

Re: Is this a "gotcha" in Python?

2019-04-22 Thread Skip Montanaro
> Not quite. The single-letter names mean "I am an iterator/index/etc", > but "_" means "I am not used anywhere". Small addendum to this. pyflakes (at least in my experience) doesn't interpret "_" as a variable name or prefix to a local variable as "unused". Skip -- https://mail.python.org/mailm

Re: Is this a "gotcha" in Python?

2019-04-22 Thread Chris Angelico
On Tue, Apr 23, 2019 at 6:18 AM DL Neil wrote: > Yet, because "i" (or "n", "a", or "x"...) does not convey usage-meaning > - other than, "I am a place-holder"! So, aren't we back to "_"? Not quite. The single-letter names mean "I am an iterator/index/etc", but "_" means "I am not used anywhere".

Re: Is this a "gotcha" in Python?

2019-04-22 Thread DL Neil
Isn't there an argument that in this context, using the single letter "l" as a variable name is 'lazy'? That the "l" could be used in different contexts (per OP). That it conveys no meaning as to the variable's purpose? In this specific case, I actually think that "l" is a bad choice, but not be

Re: Is this a "gotcha" in Python?

2019-04-22 Thread Grant Edwards
On 2019-04-20, Chris Angelico wrote: > In this specific case, I actually think that "l" is a bad choice, but > not because it's a single letter - more because there is a very strong > convention of using "i" for a loop iterator, and the lowercase "l" is > confusingly similar. Also, in some fonts

Re: Is this a "gotcha" in Python?

2019-04-20 Thread Chris Angelico
On Sun, Apr 21, 2019 at 8:43 AM DL Neil wrote: > > Be aware that this is using an old form of Python syntax, not > > supported by current versions. To try this example in a modern version > > of Python, write it like this: > > > > for l in range(50): > > print(l, end=" ") > > > Python2: print

Re: Is this a "gotcha" in Python?

2019-04-20 Thread DL Neil
On 21/04/19 8:16 AM, Chris Angelico wrote: On Sun, Apr 21, 2019 at 2:14 AM Dennis Lee Bieber wrote: Only use short (single character) names for items that only exist as loop control, and are not rebound within the loop, nor used outside of the scope of that loop (but can be reused in a

Re: Is this a "gotcha" in Python?

2019-04-20 Thread Chris Angelico
On Sun, Apr 21, 2019 at 2:14 AM Dennis Lee Bieber wrote: > Only use short (single character) names for items that only exist as > loop control, and are not rebound within the loop, nor used outside of the > scope of that loop (but can be reused in another subsequent loop > control)... > >

Re: Is this a "gotcha" in Python?

2019-04-20 Thread Jon Ribbens
On 2019-04-19, Stefan Ram wrote: > Now consider the same in Python: > > def f(): > # ... > l = 22 # representing a length > # ... > l = 'abc'; # representing the left half of something > # ... > > A Python implementation does not catch the "error". Obviously it is a deli

Re: Is this a "gotcha" in Python?

2019-04-20 Thread Ben Bacarisse
Gilmeh Serda writes: > On Fri, 19 Apr 2019 21:01:05 +, Stefan Ram wrote: > >> Has this ever been a problem for someone? > > Only for programmers who come here from other languages and expect Python > to behave in the same manner as their favorite language, so they try and > argue that thi