function with a state

Xah Lee xah at xahlee.org
Sun Mar 6 03:07:05 EST 2005


is it possible in Python to create a function that maintains a variable
value?

something like this:

globe=0;
def myFun():
  globe=globe+1
  return globe

apparently it can't be done like that. I thought it can probably be
done by prefixing the variable with some package context...

the Python doc is quite stilted. Where in the python doc is a programer
supposed read about how the package/module system in Python works?
(besides the tutorial that touches it)

 Xah
 xah at xahlee.org
 http://xahlee.org/PageTwo_dir/more.html




More information about the Python-list mailing list