L
Lonnie Princehouse
List comprehensions appear to store their temporary result in a
variable named "_[1]" (or presumably "_[2]", "_[3]" etc for nested
comprehensions)
In other words, there are variables being put into the namespace with
illegal names (names can't contain brackets). Can't someone come up
with a better hack than this? How about using "_1", "_2", etc, or
actually making "_" a list of lists and using the real first, second,
third elements? This is an unexpected wrench in the works for people
trying to implement custom global namespaces.
Illustration:
class custom_namespace(dict):
def __getitem__(self, i):
print "GET", i
return dict.__getitem__(self, i)
eval("[x for x in range(10)]", custom_namespace())
variable named "_[1]" (or presumably "_[2]", "_[3]" etc for nested
comprehensions)
In other words, there are variables being put into the namespace with
illegal names (names can't contain brackets). Can't someone come up
with a better hack than this? How about using "_1", "_2", etc, or
actually making "_" a list of lists and using the real first, second,
third elements? This is an unexpected wrench in the works for people
trying to implement custom global namespaces.
Illustration:
class custom_namespace(dict):
def __getitem__(self, i):
print "GET", i
return dict.__getitem__(self, i)
eval("[x for x in range(10)]", custom_namespace())