global/local variables

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Jan 25 06:35:32 EST 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


-- 
Steven



More information about the Python-list mailing list