Curious UnboundLocalError Behavior

bruno.desthuilliers at gmail.com bruno.desthuilliers at gmail.com
Thu Mar 1 03:20:05 EST 2007


On 28 fév, 18:15, "Matthew Franz" <mdfr... at gmail.com> wrote:
> I'm probably fundamentally misunderstanding the way the interpreter
> works with regard to scope, but is this the intended behavior...
>
(snip traceback)

> import os,sys
>
> SOMEGLOBAL=1
>
> def foo():
>     dome=False
>     if dome:
>         SOMEGLOBAL = 0


This makes SOMEGLOBAL local !-)

Look for the 'global' statement. Or better, try to avoid rebinding
globals from within a function.

As as side note: by convention, ALL_UPPER names denote constants.




More information about the Python-list mailing list