Pythons global variable
Possible Duplicate:
Using global variables in a function other than the one that created them
How can I define a global variable.
For example I have Foo1 class and Foo2 class and I want to use FooVariable in this classes as a global variable.
看到这个答案在创建它们的函数中使用全局变量
If you wanted a global variable named foo
, you would just have to put global foo
at the top of any function in which it is used. For example,
def do_something():
global foo
foo = foo + 1
print foo
Note that Python "global" variables are only global to the module they appear in, not global to the entire program (as in some languages).
链接地址: http://www.djcxy.com/p/23884.html上一篇: 读取一个文本文件并将值作为变量保存在python中
下一篇: Pythons全局变量