List comprehension - NameError: name '_[1]' is not defined ?

Terry Reedy tjreedy at udel.edu
Thu Jan 15 17:41:37 EST 2009


mario ruggier wrote:
> On Jan 15, 4:06 pm, Steven D'Aprano <st... at REMOVE-THIS-
> cybersource.com.au> wrote:
> 
> Hi Steve!
> 
>>> class GetItemEvaluator(object):
>>>     def __init__(self):
>>>         self.globals = globals() # some dict (never changes)
> 
> Ya, this is just a boiled down sample, and for simplicity I set to to
> the real globals(), so of course it will change when that changes...
> but in the application this is a distinct dict, that is entirely
> managed by the application, and it never changes as a result of an
> *evaluation*.

It would have been less confusing if you had written

              self.globals = {} # a constant dict
or even
             self.constants = {} # empty here only for simplicity

This might also make the 3.0 error message clearer (see other post).

tjr




More information about the Python-list mailing list