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

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/

你可能感兴趣的:(python,csv)