本文介绍了用 python 模仿 7zip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 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.dllcode> 并且似乎提供了仅适用于 Windows 的替代方案.

Then there is the pylib7zip library, which wraps the existing 7z.dll and seems to offer a Windows-only alternative.

这篇关于用 python 模仿 7zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 23:41