Why this throws an UnboundLocalError ?

M

Marc Aymerich

Dear all,

I have a very simple module

glic3@e4200:# cat globalstate.py
GLOBAL = 0

def update():
GLOBAL += 1


however it doesn't work!!

glic3@e4200:# python
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "globalstate.py", line 4, in update
GLOBAL += 1
UnboundLocalError: local variable 'GLOBAL' referenced before assignment


And I don't know why :(
Anyone ?

Thanks!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top