Joh*_*. M 4 python gzip python-3.x
我一直在寻找一种可以在 python 中读取 gz 文件的方法,我做了类似的事情
with gzip.open(filepath) as infile: ...
然而,读入的数据似乎是字节状的,我不能做类似的事情for l in infile。有办法解决这个问题吗?
for l in infile
Joe*_*don 6
将mode='rt'(文本模式)传递给呼叫gzip.open。
mode='rt'
gzip.open
从文档(上面链接):
模式参数可以是二进制模式或文本模式中的任何一个'r', 'rb', 'a', 'ab', 'w', 'wb', 'x'。默认为.'xb''rt', 'at', 'wt','xt''rb'
'r', 'rb', 'a', 'ab', 'w', 'wb', 'x'
'xb'
'rt', 'at', 'wt',
'xt'
'rb'
归档时间:
7 年,4 月 前
查看次数:
5366 次
最近记录: