使用python 3提取7z文件 [英] extract 7z file using python 3

查看:39
本文介绍了使用python 3提取7z文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 python 解压缩 7z 文件,但我似乎无法弄清楚.我想我可以在 python 3 中使用 lzma 模块,但我似乎无法弄清楚:

I was trying to decompress a 7z file using python, but I can't seem to figure it out. I figured I could use the lzma module in python 3, but I can't seem to figure it out:

我认为它会像 zipfile 包一样工作:

I thought it would work like the zipfile package:

import lzma
with lzma.open('data.7z') as f:
    f.extractall(r"<output path>")

但在阅读文档后,似乎没有.所以这是我的问题:如何使用标准包提取 7z 文件?我不想调用 subprocess 使用 7-zip 解压文件,因为我不能保证用户安装了这个软件.

but after reading the documents, it doesn't seems to. So here is my question: How can you extract a 7z file using the standard package? I don't want to call subprocess to extract the files using 7-zip because I can't guarantee that users have this software installed.

我搜索了互联网和堆栈 oerflow,并注意到所有的答案几乎都回到使用子处理,我想避免像瘟疫一样.

I've searched the internets and stack oerflow and noticed all the answers almost go back to using subprocessing which I would like to avoid like the plague.

虽然在stackoverflow上也有类似的问题,但答案仍然取决于7-zip或7zip SDK.我不想使用 7-zip sdk/exe 进行提取,因为这假设用户已安装该软件.

Though there are similar questions on stackoverflow, the answers all still depend on 7-zip or the 7zip SDK. I do not want to use the 7-zip sdk/exe for extraction because that assumes the users have the software installed.

这是 7z 文件中的属性:

Here is the properties from the 7z file:

推荐答案

试试这个怎么样?:

from pyunpack import Archive
Archive('data.7z').extractall("<output path>")

这篇关于使用python 3提取7z文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆