在Windows上使用Python连接压缩文件 [英] Concatenate gzipped files with Python, on Windows
本文介绍了在Windows上使用Python连接压缩文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Windows上,是否有一种内存有效的方法可以使用Python在不解压缩的情况下连接压缩文件?
Is there a memory-efficient way to concatenate gzipped files, using Python, on Windows, without decompressing them?
根据对答案,它应该很简单:
According to a comment on this answer, it should be as simple as:
cat file1.gz file2.gz file3.gz > allfiles.gz
但是如何在Windows上使用Python做到这一点?
but how do I do this with Python, on Windows?
推荐答案
只需继续写入同一文件即可。
Just keep writing to the same file.
with open(..., 'wb') as wfp:
for fn in filenames:
with open(fn, 'rb') as rfp:
shutil.copyfileobj(rfp, wfp)
这篇关于在Windows上使用Python连接压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文