python的作用域有关问题
python的作用域问题Python code def func():t.start()# 为什么在函数内部可以使用定义在函数外面的对象
python的作用域问题
Python code>>> def func(): t.start() # 为什么在函数内部可以使用定义在函数外面的对象t? for i in range(5): print(i) >>> t = Mythread(2) <-- t是在函数外面定义的>>> func()01234>>> 2
[解决办法]python变量作用域遵循一个称为LGB的规则,
This is the so-called LGB rule of name resolution: local, then global, then built-in.
请参考:
http://www.magicalboy.com/python-scope-legb.html
http://www.manaware.net/language-processing/variable-scope.html