用Python模拟7zip [英] Mimic 7zip with python
问题描述
我正在使用Python 3.6,目前我对7zip程序进行子处理以获取所需的压缩。
I am using Python 3.6, and currently I subprocess out to my 7zip program to get the compression I need.
subprocess.call( '7z a -t7z -ms = off {0} *'。format(filename))
我知道zipfile类具有'ZIP_LZMA '压缩,但是我通过的应用程序也说输出文件不正确。那么,我还需要添加什么到ZipFile类中以使其模仿上面的命令?
I know the zipfile class has ‘ZIP_LZMA’ compression, but the application I am passing this too says the output file isn’t correct. So what else do I have to add to the ZipFile class to make it mimic the above command?
推荐答案
如果您不在乎对于Windows而言,它可能有很多帮助,那么 libarchive 可能会有所帮助。例如,在Ubuntu中:
If you do not care much for Windows, then perhaps libarchive could help. In Ubuntu, for example:
$ sudo apt install python3-libarchive-c
然后:
import libarchive
with libarchive.file_writer('test.7z', '7zip') as archive:
archive.add_files('first.file', 'second.file', 'third.file')
然后有 pylib7zip 库,该库包装了现有的 7z.dll
,并且似乎提供了仅Windows的替代方法。
Then there is the pylib7zip library, which wraps the existing 7z.dll
and seems to offer a Windows-only alternative.
这篇关于用Python模拟7zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!