好的我正在做一些線程,我猜想當我開始進行線程化時,我認爲你不能像定義那樣返回值(它是一天的結束,我的大腦是即將死去,所以也許這是不正確的,我應該開始要回擺脫全局變量)全局變量和模塊(簡單示例幫助)Python
反正我有一個測試程序,以弄清楚爲什麼我不能模塊化我的代碼
一個文件名爲config .py
a_variable=0
一個名爲test_for_sean.p的文件Ÿ
from config import *
def blah():
global a_variable
a_variable=14
return 0
一個名爲main.py文件
from config import *
from test_for_sean import *
print a_variable #this prints correctly
blah()
print a_variable #this is still printing 0....
有人聯繫我的東西,所以我不殺了自己
我不建議做一個'''import *'''。也許'''將test_for_sean導入爲tfs'''。這會導致各種各樣的問題 - 比如config.py是如何執行兩次的,它會填充它導入的兩個腳本的全局命名空間。 – FakeRainBrigand
@FakeRainBrigand我在看這個http://www.etsimo.uniovi.es/python/infogami-faq/programming/how-do-i-share-global-variables-across-modules/是否真的錯了? –
我的錯誤。我在config.py中使用''print''進行測試,它只運行一次。 – FakeRainBrigand