我使用以下代码作为解析FCC License View示例数据集的概念证明:
import csv
if __name__ == '__main__':
csv_file = open('fcc-license-view-data-sample.csv', 'rb')
dialect = csv.Sniffer().sniff(csv_file.read(1024))
csv_file.seek(0)
data = csv.DictReader(csv_file, dialect=dialect)
for item in data:
print item
模块打印完所有数据后,抛出异常:
File "C:\Python27\lib\csv.py", line 104, in next row = self.reader.next()
_csv.Error:字符串内的换行符
为什么会出现这个异常?我怎样才能避免它?