global variables

Björn Buth bjoern4562000 at yahoo.de
Fri Oct 12 08:25:36 EDT 2001


Hi there,

I´m experiencing a little problem due to my
poor understanding of the way python handles
global variables. Basically the problem is the following
I have a programm with several variables which
I would like to access globaly.

--

var=0
def example_function()
    var=var+1
     (function definition)
print example_function(10)

will give an error: UnboundLocalError: local variable 'steine' referenced
before assignment. Also replacing the first line by

global var
var=0

won´t work either. How can I get variables to work globally ?
thanks

bjoern





More information about the Python-list mailing list