我的代码突然开始在每个变量上抛出UnboundLocalError:
。
为什么突然这样做?
我是否需要在allowed_domains
之外定义try:
,如果是,为什么以前不会导致错误?
感谢。
File "/spiders/functions.py", line 85, in getAllowedDomains
return (allowed_domains)
UnboundLocalError: local variable 'allowed_domains' referenced before assignment
代码:
def getAllowedDomains():
try:
connection = lite.connect('links.db')
c = connection.cursor()
c.execute("SELECT site from sites")
all_rows = c.fetchall()
allowed_domains = []
for row in all_rows:
url = row[0]
url = url[7:]
print 'allowed url: '
print url
allowed_domains.append(url)
except lite.Error, e:
print "Error %s:" % e.args[0]
finally:
if connection:
connection.close()
return (allowed_domains)