你如何使用python 2.7迭代一个gzipped回车文件?

the*_*kid 6 python gzip python-2.7

我必须使用python 2.7,因为我使用的是boto库,而boto3是实验性的.我需要读取一个gzip压缩的文件,并通过回车符终止行.使用python 3.3看来你可以在gzip.open中指定换行变量.在python 2.7中这样做最干净,最有效的方法是什么.

jfs*_*jfs 13

您可以尝试io使用通用换行支持逐行读取gzip压缩文件的模块:

import gzip
import io

with io.TextIOWrapper(io.BufferedReader(gzip.open(filename))) as file:
    for line in file:
        print line,
Run Code Online (Sandbox Code Playgroud)