使Python 3异常向后兼容

3

这段代码块(来自PEP 3109)的向后(尽可能是2.6)兼容语法是什么:

try:
   self.spawn(pp_args)
except DistutilsExecError as msg:
   raise CompileError from msg
1个回答

0

这是在Python 2.x中最接近的写法:

try:
   self.spawn(pp_args)
except DistutilsExecError as msg:
    print "DistutilsExecError : " + str(DistutilsExecError(msg))
    print
    print "The above exception was the direct cause of the following exception:"
    raise CompileError

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