【发布时间】:2011-05-20 04:11:17
【问题描述】:
如果“x”存在,则打印“x 存在”。
我问这个是因为我总是收到这个错误:
UnboundLocalError at /settings/
local variable 'avatarlink' referenced before assignment
【问题讨论】:
-
重申:一般情况下,不要使用
locals(),globals(),不要抓UnboundLocalError,而是修复你的代码。请阅读答案 stackoverflow.com/questions/575196/… 中提供的 Python 中范围、命名空间、命名和绑定的链接 -
-1:如果您总是收到此错误,则说明您有设计问题。您不需要“测试”变量,您需要修复您的设计。为什么您“总是”收到此错误?你犯了什么设计错误?
-
How do i check if a variable exists in python 的标题几乎与此相同。这两个问题有什么不同吗?
标签: python debugging variables object