Re: Curious UnboundLocalError Behavior
- From: "Daniel Nogradi" <nogradi@xxxxxxxxx>
- Date: Wed, 28 Feb 2007 18:33:35 +0100
I'm probably fundamentally misunderstanding the way the interpreter
works with regard to scope, but is this the intended behavior...
[....]
SOMEGLOBAL:
Traceback (most recent call last):
File "unboundlocal.py", line 15, in ?
foo()
File "unboundlocal.py", line 11, in foo
print "SOMEGLOBAL:",SOMEGLOBAL
UnboundLocalError: local variable 'SOMEGLOBAL' referenced before assignment
[......]
import os,sys
SOMEGLOBAL=1
def foo():
dome=False
if dome:
SOMEGLOBAL = 0
print globals()
print "SOMEGLOBAL:",SOMEGLOBAL
print os.uname()
print sys.version
foo()
Try:
import os,sys
SOMEGLOBAL=1
def foo():
global SOMEGLOBAL
dome=False
if dome:
SOMEGLOBAL = 0
print globals()
print "SOMEGLOBAL:",SOMEGLOBAL
print os.uname()
print sys.version
foo()
HTH,
Daniel
.
- Prev by Date: Re: finding out the precision of floats
- Next by Date: Re: finding out the precision of floats
- Previous by thread: Curious UnboundLocalError Behavior
- Next by thread: Writing an interpreter for language similar to python!!
- Index(es):
Relevant Pages
|