扫码关注官方订阅号
try: print(aaa) except Exception as e: print(e)
业精于勤,荒于嬉;行成于思,毁于随。
import sys, os try: raise NotImplementedError("No error") except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
提问前请先上网搜索。
python-when-i-catch-an-exception-how-do-i-get-the-type-file-and-line-number
建议研究一下traceback模块
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
提问前请先上网搜索。
python-when-i-catch-an-exception-how-do-i-get-the-type-file-and-line-number
建议研究一下traceback模块