【发布时间】:2019-09-01 03:29:03
【问题描述】:
我正在尝试逐行解析 gzip 文件:
with gzip.open(obj.get()['Body'])as f:
for line in f:
line=StringIO(line.decode("utf-8"))
line=csv.reader(line,delimiter=',')
for line1 in line:
#some logic
但是对于某些文件我有错误:
new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
当我尝试以换行模式打开时:
csv.reader(open(line, 'rU'), delimiter=',')
我有:
expected str, bytes or os.PathLike object, not _io.StringIO
我希望所有包含 '\r' 的字段都作为字符串值的一部分出现在该字段中。 如何解决?
【问题讨论】:
-
你用的是什么版本的python?
-
我用的是3.7.1版