runtime-error - Pythonwin.exe 不指出运行时错误的代码行
问题描述
这是一个棘手的问题,因为它处理的是 Pythonwin.exe 用户界面本身,而不是我的代码。
当我运行一个包含以下代码的文件时,我希望如果它出错,它会在回溯输出中显示它失败的行
我实际上只是创建了一个未受污染的 32 位 python 3.5 环境,安装了 pywin32,然后打开了我的 testfile.py 来运行它,结果如下。 截屏
如果你看到这行说
File "C:\testfile.py", line 2, in <module>
foo = 2 #this line works fine, but is identified as the traceback line
我本来希望这指向第 5 行而不是第 2 行。在更大的脚本中,这会产生更大的问题,因为我需要根据上下文猜测是哪一行导致了错误。
在基于 anaconda 的环境中复制我的情况: 1. 打开 Anaconda 命令提示符 2. 运行以下行来生成我们的环境
set CONDA_FORCE_32BIT=1
conda create -n test python=3.5
activate test
conda install -y pywin32
- 用文本保存“testfile.py”文件:
#comment foo = 2 #this line works fine, but is identified as the traceback line a=2 a=3 a=b #this line causes the error, but isn't identified
- 打开 PythonWin.exe,打开“testfile.py”文件并按 F5 或单击运行
这不仅仅是 anaconda 安装环境中的问题。如果有人知道如何让它报告错误的代码行,或者它为什么会这样,请告诉我。谢谢!
解决方案
推荐阅读
- elasticsearch - 副本和分片设置未在弹性搜索模板中应用
- python - 在什么情况下 print('done') 语句会执行而不执行?
- python - 如果单行文本有多个标签,有没有办法将文本包装在一个标签中?
- c# - 为什么我的程序的内存使用量快速上升然后变平?
- python - 如果输入满足特定条件,则池化 LSTM 输出
- python - Python Open CV 错误:名称错误:未定义名称图像
- google-bigquery - 如何获取所有 BigQuery (bq) 命令历史记录?
- javascript - 内置 Javascript 函数的模拟结果
- ios - Xcode 开发团队未显示(无法找到您所属的具有给定团队 ID 'xxxxxx' 的团队。)
- angular - 将winston日志添加到电子角度应用程序时出错