yeg*_*gle 11 python python-3.x
反正有没有编写一个从python 2.4到python 3兼容的异常捕获代码?
喜欢这段代码:
# only works in python 2.4 to 2.7
try:
pass
except Exception,e:
print(e)
# only works in python 2.6 to 3.3
try:
pass
except Exception as e:
print(e)
Run Code Online (Sandbox Code Playgroud)
nne*_*neo 16
试图编写适用于Python 2和Python 3的代码最终是徒劳的,因为它们之间存在着巨大的差异.实际上,现在许多项目都在单独的Python 2和Python 3版本中进行维护.
也就是说,如果你是以一种超级便携的方式做到这一点......
import sys
try:
...
except Exception:
t, e = sys.exc_info()[:2]
print(e)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5830 次 |
| 最近记录: |