scope question
Mark Robinson
m.1.robinson at herts.ac.uk
Tue Aug 7 12:18:04 EDT 2001
Thanks, I was trying to write
global count += 1
which didn't help, got it now :)
Terry Reedy wrote:
>> count = 0
>> def function():
>> print count
>> function()
>> #works fine, however, if I type this:
>>
>> count = 0
>> def function():
>> count += 1
>> print count
>> function()
>>
>> UnboundLocalError: local variable 'count' referenced before
>
> assignment
>
> 1. Read the manual on variables in function bodies.
> 2. Binding name anywhere in function body makes it local unlesss you
> declare it global:
> global count
>
> Terry J. Reedy
More information about the Python-list
mailing list