这是我的python2代码,需要移植:
try:
do_something_with_file(filename)
except:
exc_type, exc_inst, tb = sys.exc_info()
exc_inst.filename = filename
raise exc_type, exc_inst, tb
通过上面的代码,我可以通过检查异常是否具有“filename”属性来获取问题输入文件的整个异常。
然而,Python3号的加薪已经改变。这就是2to3给我的上述代码:
except Exception as e:
et, ei, tb = sys.exc_info()
e.filename = filename
raise et(e).with_traceback(tb)
这又给了我一个错误,我不认为文件名属性被保留:
in __call__
raise et(e).with_traceback(tb)
TypeError: function takes exactly 5 arguments (1 given)
我只想用一些信息透明地传递异常来跟踪输入文件。我想念Python的raise [exception_type[,exception_instance[,traceback]]]
-我怎么能在Python3里做到这一点?
目前没有回答
相关问题 更多 >
编程相关推荐