通过.traceback.tb_lineno获取 try: print(asd) except Exception as e: print('Except:',e,"Line:",e.__traceback__.tb_lineno)