使python 3异常向后兼容

时间:2013-11-21 15:29:21

标签: python python-3.x syntax compatibility python-2.x

此代码块的后向(如果可能的话)2.6兼容语法是什么(来自PEP 3109):

try:
   self.spawn(pp_args)
except DistutilsExecError as msg:
   raise CompileError from msg

1 个答案:

答案 0 :(得分: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