比如在我的程序中
from other import do_sth
在 other.do_sth 中
有类似于
```
a = 0
def do_sth ():
global a
a = 2
```
那么如果我要在我的程序中用到 a 和 do_sth , 如何使用才能正确获得被 do_sth 修改过的 a 值?
我试过了:
1. from other import do_sth, a
2. from other import do_sth
a = 0 (本地定义了一个不在任何 block 之内的 a ,所谓的全局?)
都没有用。。。
前提是不改变other的情况下
类似于
test1.py
=========
a = 2
def app ():
global a
a = a + 1
return
=========
test2.py
=========
from test1 import app, a
print a
app
print a
=========
from other import do_sth
在 other.do_sth 中
有类似于
```
a = 0
def do_sth ():
global a
a = 2
```
那么如果我要在我的程序中用到 a 和 do_sth , 如何使用才能正确获得被 do_sth 修改过的 a 值?
我试过了:
1. from other import do_sth, a
2. from other import do_sth
a = 0 (本地定义了一个不在任何 block 之内的 a ,所谓的全局?)
都没有用。。。
前提是不改变other的情况下
类似于
test1.py
=========
a = 2
def app ():
global a
a = a + 1
return
=========
test2.py
=========
from test1 import app, a
print a
app
print a
=========