我一直在使用WinPython編碼,使用一個全局變量的程序,這是代碼:,這是正常的行爲嗎?
def main():
global listC
listC=[1,2,3,4,5]
def doSomething():
if listC!=[]:
pass
,我有這樣的問題,說如果listC = ...拋出我行!警告說「未定義名稱listC」;這個程序實際上編譯和執行正常,但我想知道爲什麼如果我已經聲明列表作爲一個全局變量的警告。
我想通過以下方式來執行它:
programName.main() //init the list
programName.doSomething() //do an operation with the list
programName.doSomething() //same as before
...
感謝
我必須同意下面的jsbueno,在doSomething()中必須發生其他事情。你發佈的代碼工作正常。 – whitebeard 2014-08-28 01:48:57