python - VS2013中的PTVS : Why does this for loop not catch the StopIteration?

标签 python python-3.x visual-studio-2013 ptvs

我在 VS2013 中使用 PTVS 和 Python 3.4.1。

以下代码尝试读取文件末尾并在 VS2013 中引发 StopIteration 异常。它在Python解释器中运行良好。

source.csv 是一个从 Excel 2013 保存为 csv 的简单 csv 文件。

csvreader.py:

import csv

with open(r"c:\data\source.csv", "r") as reader:
    csvreader = csv.DictReader(f=reader, dialect = 'excel')
    for row in csvreader:
        print(row)

源.csv:

Col1,Col2,Col3
a1,a2,a3
b1,b2,b3

最佳答案

无论如何,

StopIteration 都会在那里引发,只是 VS 实际上向您显示了它引发的点。这并不意味着异常未处理 - 如果您从该点继续运行,您会发现它的工作原理完全相同。

现在,默认情况下它不应该报告此异常(“调试”->“异常”中的默认设置是“报告未处理”,因此只有在实际未处理时才应报告该异常)。如果您使用 PTVS 2.0,那么您很可能会点击 this bug 。我建议切换到 2.1 beta ,它解决了这个问题以及其他许多问题。

关于python - VS2013中的PTVS : Why does this for loop not catch the StopIteration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24177956/

相关文章:

python - 是否有用于编辑 msword 文档文件的 python 库?

c# - 选定的选项

python - Django 设置文件中的 Django 错误 - TypeError : expected str, 字节或 os.PathLike 对象,而不是元组

python - PyPDF2 : writing output to stdout fails with python3

python - 使用 pd.DataFrame.to_excel 时旋转单元格的文本?

html - 如何使用 Python 将 HTML 代码复制到剪贴板?

sql-server - VS SQLCLR : Function X has unresolved reference to schema Y

.net - Visual Studio 测试资源管理器错误 : An exception occurred while initializing the database. 有关详细信息,请参阅 InnerException

python - 生成 ODT/DOC(X) 并转换为 PDF,无需 OO.o/MS

python - 让移动更真实