> On Monday 20 October 2003 04:30 pm, Guido van Rossum wrote: > > > We are indeed sure (sadly) that list comprehensions leak control variable > > > names. > > > > But they shouldn't. It can be fixed by renaming them (e.g. numeric > > names with a leading dot). > > Hmmm, sorry? > > >>> [.2 for .2 in range(3)] > SyntaxError: can't assign to literal > > I think I don't understand what you mean. I meant that the compiler should rename it. Just like when you use a tuple argument: def f(a, (b, c), d): ... this actually defines a function of three (!) arguments whose second argument is named '.2'. And the body starts with something equivalent to b, c = .2 For list comps, the compiler could maintain a mapping for the listcomp control variables so that if you write [x for x in range(3)] it knows to generate bytecode as if x was called '.7'; at the bytecode level there's no requirement for names to follow the identifier syntax. --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4