NameError,使用try时未定义全局,但 [英] NameError, global not defined when using try,except

查看:122
本文介绍了NameError,使用try时未定义全局,但的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:

忽略此内容,我在发布此消息后大约3秒钟就发现了它,但无法将其删除=(


Ignore this, I figured it out about 3 seconds after posting this but can't delete it =(

尝试此操作,除了使用RackSpace云文件的代码

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)

如果未找到 file.jpg,则会引发异常 NoSuchObject。运行此代码时,我会得到错误

If 'file.jpg' is not found, the exception 'NoSuchObject' is raised. When I run this code I get the error


除了NoSuchObject作为对象名:

NameError:未定义全局名称'NoSuchObject'

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.

推荐答案

facepalm

是的,这只是我的编程工作,没什么大事

Yeah this programming thing's only my job, nothing big

我必须使用愚蠢的东西我

I have to use the stupid thingy thing don't I

try:
    cacheobject = cachecontainer.get_object('file.jpg')
except cloudfiles.errors.NoSuchObject as objectname:
    raise tornado.web.HTTPError(404)

我会努力的,以后不要傻

I'll try and not be stupid in future

这篇关于NameError,使用try时未定义全局,但的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆