UnboundLocalError: local variable 'blah' referenced before assignment

Emile van Sebille emile at fenx.com
Mon Jun 3 18:38:16 CEST 2002


Daniel
> I have a strange problem where a global variable is no longer
> referenced.
> Stripped down, it's something to the effect of:
>
> def func1():
>    blah='bcd'
>
> def func2():

insert global blah here

>    print blah
>    blah='cde'

this assignment causes blah to be interpreted as a local within func2,
so the print (local) blah above occurs before blah has a value.  Adding
the global blah identifies that blah is not local, allowing the global
value to be used.


--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list