Newbie: How to create a global or static variable?
Adrian Eyre
a.eyre at optichrome.com
Mon Jan 31 11:11:12 EST 2000
> 1 - How do I create a global variable in a script that is in scope for
> all the functions defined in the script?
myGlobal = "spam"
def changeMyGlobal(what):
global myGlobal
myGlobal = what
print myGlobal
changeMyGlobal("eggs, bacon and spam")
print myGlobal
> 2 - Can I create a static variable with an initial assignment in a
> function?
No. You'll have to use either class attributes, or globals (or some
other Python hackery.)
--------------------------------------------
Adrian Eyre <a.eyre at optichrome.com>
http://www.optichrome.com
More information about the Python-list
mailing list