Python csv模块读文件错误 _csv.Error: new-line character seen in unquoted field

来源:互联网 发布:电影下载软件 编辑:程序博客网 时间:2024/05/21 17:55

csv模块读取文件报错:

_csv.Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?

解决:
open文件时使用 universal newline mode,在open()方法中使用 ‘U’ or ‘rU’ ,例如:

spamreader = csv.reader(open(f, 'rU'), delimiter=',')

universal newline mode 接受 \n, \r, and \r\n 作为换行符。

转载自:http://slaptijack.com/programming/python-csv-error-on-new-line-character-in-unquoted-field/

阅读全文
0 0