Exception message (Python 2.6)

后端 未结 4 1266
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 10:02

In Python, if I open a binary file that doesn\'t exist, the program exits with an error and prints:

Traceback (most recent call last):
  File \"C:\\Python_te         


        
4条回答
  •  囚心锁ツ
    2020-12-05 10:33

    Python has the traceback module.

    import traceback
    try:
        pkl_file = open('monitor.dat', 'rb')
        monitoring_pickle = pickle.load(pkl_file)
        pkl_file.close()
    except IOError:
        traceback.print_exc()
    

提交回复
热议问题