NameError,使用try时未定义全局,除非
编辑:
忽略这个,我在发布这个后大约 3 秒就发现了它,但无法删除它 =(
我有这个尝试,除了用于使用 RackSpace cloudfiles 的代码
try:
cacheobject = cachecontainer.get_object('file.jpg')
except NoSuchObject as objectname:
raise tornado.web.HTTPError(404)
如果找不到“file.jpg”,则会引发“NoSuchObject”异常当我运行此代码时,我收到错误
除了 NoSuchObject 作为对象名:
NameError:未定义全局名称“NoSuchObject”
我尝试将 NoSuchObject 放在引号中,但随后收到有关字符串异常被折旧的错误。
Edit:
Ignore this, I figured it out about 3 seconds after posting this but can't delete it =(
I have this try, except code for working with RackSpace cloudfiles
try:
cacheobject = cachecontainer.get_object('file.jpg')
except NoSuchObject as objectname:
raise tornado.web.HTTPError(404)
If 'file.jpg' is not found, the exception 'NoSuchObject' is raised. When I run this code I get the error
except NoSuchObject as objectname:
NameError: global name 'NoSuchObject' is not defined
I tried putting NoSuchObject in quotes but then I got an error about string exceptions being depreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你尝试过显式导入吗?像这样 :
did you try with an explicit import ? like this :
NoSuchObject 在另一个模块中,可能在缓存容器中。你必须导入它。
NoSuchObject is in another module, probably in cachecontainer. You have to import it.
捂脸
是的,这个编程只是我的工作,没什么大不了的,
我必须使用愚蠢的东西,不是吗?我
会尝试,将来不再愚蠢
facepalm
Yeah this programming thing's only my job, nothing big
I have to use the stupid thingy thing don't I
I'll try and not be stupid in future