scope question
Terry Reedy
tjreedy at home.com
Tue Aug 7 11:16:24 EDT 2001
> 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