why does this not work!!! AAARRRGH!!!!!!!!
Maurizio Turatti
mturatti at yahoo.com
Thu Sep 28 10:55:42 EDT 2000
You misunderstand the "global" statement, try this:
myglobalvar = 101
def myfunc():
global myglobalvar
myglobalvar = myglobalvar + 1
myfunc()
print myglobalvar
Here you say in myfunc that you are changing the global variable
"myglobal".
Maurizio
Matthew Banham wrote:
>
> why does the following code (declared in a module) not work when I call
> myfunc?
>
> global myglobalvar
> myglobalvar = 101
>
> def myfunc():
> myglobalvar = myglobalvar + 1
>
> It gives an Unbound Local Error in the myglobalvar = myglobalvar + 1 line
>
> It's driving me madd
> aaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrggggggggggggggghhhhhhhhhhh!!!!!!!!!!!!!!!!
>
> Yours Sincerely,
> Matthew Banham
>
> ----------------------------------------------------------------------------
> ----
> Matthew Banham, MSci
> Development Engineer & Technical Support Officer
>
> Photon Design Tel: +44 1865 395480
> 68 Church Way Fax: +44 1865 395481
> Iffley, Oxford Email: matb at photond.com
> OX4 4EF Web: www.photond.com
More information about the Python-list
mailing list