UnboundLocalError: local variable '_[1]' referenced before assignment

Hrvoje Niksic hniksic at xemacs.org
Wed Dec 9 09:48:27 EST 2009


Richard Thomas <chardster at gmail.com> writes:

> That isn't an error that should occur, not least because _[1] isn't a
> valid name. Can you post a full traceback?

The name _[n] is used internally when compiling list comprehensions.
The name is chosen precisely because it is not an (otherwise) valid
identifier.  For example, try:

import dis
dis.dis(lambda: [ a for a in l ])

The user should never see _[n]; if he does, it's probably due to a bug
in Python.



More information about the Python-list mailing list