我一直在使用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