gpt4 book ai didi

python - 用 python 模拟 7zip

转载 作者:太空狗 更新时间:2023-10-30 01:36:21 25 4
gpt4 key购买 nike

我正在使用 Python 3.6,目前我对我的 7zip 程序进行子处理以获得我需要的压缩。

subprocess.call('7z a -t7z -ms=off {0} *'.format(filename))

我知道 zipfile 类有“ZIP_LZMA”压缩,但我传递给它的应用程序也说输出文件不正确。那么我还必须向 ZipFile 类添加什么才能使其模仿上述命令?

最佳答案

如果您不太喜欢 Windows,那么也许 libarchive有帮助。在 Ubuntu 中,例如:

$ 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 的替代方案。

关于python - 用 python 模拟 7zip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50424946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com