global/local variables

Steven D'Aprano steve at
Fri Jan 25 12:35:32 CET 2008

On Fri, 25 Jan 2008 03:28:05 -0800, Tim Rau wrote:

>> Because you don't assign to allThings, and therefore it is treated as
>> global.
> Hmm.... so I can't assign to globals in a  local environment? How do I
> make it see that I'm assigning to a global?

I thought somebody had already mentioned this... possibly even me... 

You can declare a name as global by using the global statement:

def foo():
    global x
    x += 1


More information about the Python-list mailing list