python 捕获异常详细信息
import os import sys import traceback BasePath = os.path.dirname(os.getcwd()) sys.path.append(BasePath) from src import main if __name__ == '__main__': try: main.run() except Exception as e: with open('error.log','a') as f: f.write('*' * 100 + "\n") f.write(traceback.format_exc()) # 使用 traceback.format_exc() 获取异常详细信息 f.write('*' * 100 + "\n")