【问题标题】:making python 3 exception backward compatible使python 3异常向后兼容
【发布时间】:2013-11-21 15:29:21
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    这和你在 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多