[Python-Dev] Improve error message "UnboundLocalError: local variable referenced before assignment"

Jan Matějek jmatejek at suse.cz
Mon Nov 12 16:30:41 CET 2012

Dne 31.10.2012 23:15, Steven D'Aprano napsal(a):

>> I wonder if this message can be improved with a
>> pointer to the concept on when global variables become local?
> If you have a suggestion for an improved message, please tell us. Or raise
> an issue on the bug tracker.

I believe the "human problem" here is that the one tends to gloss over "local 
variable VARNAME", because it describes VARNAME and you already think you know 
what that is, so you don't stop to think about it.

The following would be better in this regard, IMO:

"Variable VARNAME is local in FUNCNAME, but doesn't have a value at line 123"


More information about the Python-Dev mailing list