此代码块(来自 PEP 3109)的向后(2.6,如果可能)兼容语法是什么:
try:
self.spawn(pp_args)
except DistutilsExecError as msg:
raise CompileError from msg
最佳答案
这与您在 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
关于python - 使 python 3 异常向后兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20125039/