Mimic 7zip with python

£可爱£侵袭症+ 提交于 2020-05-26 04:09:11

问题


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))

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?


回答1:


If you do not care much for Windows, then perhaps libarchive could help. In Ubuntu, for example:

$ sudo apt install python3-libarchive-c

Then:

import libarchive
with libarchive.file_writer('test.7z', '7zip') as archive:
    archive.add_files('first.file', 'second.file', 'third.file')

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



来源:https://stackoverflow.com/questions/50424946/mimic-7zip-with-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!