使python3异常向后兼容

2024-06-24 08:15:43 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

Tags: 代码fromselfas语法argsmsgpep
1条回答
网友
1楼 · 发布于 2024-06-24 08:15:43

这与您在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

相关问题 更多 >