我需要讀入並處理一堆〜40mb gzip文本文件,並且我需要它快速完成並且I/O開銷最小(因爲其他人也使用這些卷)。我這樣找到了這個任務,最快的方式是這樣的: def gziplines(fname):
f = Popen(['zcat', fname], stdout=PIPE)
for line in f.stdout:
yield line
然後: for
如果我的gz文件不存在,爲什麼不這樣做呢? $ cat test.pl
open(FILE, "zcat dummy.gz |") or die "DIE";
$ ./test.pl
zcat: dummy.gz: No such file or directory
如果我讀文件通常,它按預期工作: $ cat test2.pl
open(FILE, "dummy.gz") o