Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65060 > unrolled thread

Re: Why this throws an UnboundLocalError ?

Started byMark Lawrence <breamoreboy@yahoo.co.uk>
First post2014-01-30 22:53 +0000
Last post2014-01-30 22:53 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Why this throws an UnboundLocalError ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-30 22:53 +0000

#65060 — Re: Why this throws an UnboundLocalError ?

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-01-30 22:53 +0000
SubjectRe: Why this throws an UnboundLocalError ?
Message-ID<mailman.6174.1391122453.18130.python-list@python.org>
On 30/01/2014 22:46, Marc Aymerich wrote:
> 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.
>>>> import globalstate
>>>> globalstate.update()
> 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!!
>

You must tell the update function that GLOBAL is global.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web