问题
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.
回答1:
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
回答2:
NoSuchObject is in another module, probably in cachecontainer. You have to import it.
回答3:
did you try with an explicit import ? like this :
from cloudfiles.errors import NoSuchObject
来源:https://stackoverflow.com/questions/6060865/nameerror-global-not-defined-when-using-try-except