Python Scoping: Run it over me one more time please...
dworkin at ccs.neu.edu
Fri Mar 24 22:18:24 CET 2000
"Warren Postma" <embed at geocities.com> writes:
> # But why can't this function modify the global Y:
> Y = 0
> def inc_Y():
> Y= (Y + 1)
> return Y
It can, if you add one line.
>>> Y = 0
>>> def inc_Y():
... global Y
... Y= (Y + 1)
... return Y
Python, in examining your function, saw that you are modifying Y and
decided that it is local. You just need to tell it that Y is a
This sort of thing is mentioned a couple of times in the FAQ.
More information about the Python-list