當我運行了以下功能:的Python - 古怪的UnboundLocalError
def checkChange():
for user in userLinks:
url = userLinks[user]
response = urllib2.urlopen(url)
html = response.read()
我得到
Traceback (most recent call last):
File "InStockBot.py", line 34, in <module>
checkChange()
File "InStockBot.py", line 24, in checkChange
html = response.read()
UnboundLocalError: local variable 'response' referenced before assignment
這是沒有意義的我。我沒有全局變量響應。通常情況下,我希望它能像以下那樣工作。
>>> url="http://google.com"
>>> response = urllib2.urlopen(url)
>>> html = response.read()
>>> html
'<!doctype html>
任何人都知道爲什麼會出現此錯誤?
你能發佈你所有的代碼嗎? – Blender
它在這裏:http://pastebin.com/n04NGRYv – TheoretiCAL