下面的打印出"None"而不是"whatever"。我不明白为什么。
dirr = None
def method():
global dirr # you have to declare that you'll use global variable 'dirr'
dirr = "whatever"
print `dirr`
你应该调用'method'一次。
dirr = None
def method():
global dirr # you have to declare that you'll use global variable 'dirr'
dirr = "whatever"
method()
print (dirr)
结果是:
whatever