如何在Python 2.5中将异常赋值给本地变量?

8
在Python 2.6+中,您可以像这样处理异常:
  try:
    # stuff
  except Exception as e:
    return 'exception %s' % type(e)

2.5版本中的等价物是什么?

1个回答

13

像这样:

try:
    # stuff
except Exception, e:
  return 'exception %s' % type(e)

2
我觉得你不需要调用str(),因为你已经在使用%s进行插值了,'exception %s' % type(e)会很好地工作。 - mouad
已编辑我的问题。 :) - Josh Glover

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接