import gzip with open('file.jsonl') as f_in: with gzip.open('file.jsonl.gz', 'wb') as f_out: f_out.writelines(f_in) Run Code Online (Sandbox Code Playgroud) gzip.open()用于打开 gzip 压缩文件,而不是 jsonl。 读: 在Python 中 gzip 文件 Python 对 Gzip 的支持归档...
示例1 defread_extractions(extractions):# Get the number of lines (docs) to process# Do this before re-opening the file because read_jsonlines()# returns a generator.withopen(extractions)asf:l=f.readlines()ndocs=len(l)f.close()# Read in the JSON file (contains, among other things, ...