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

查看:370
本文介绍了使用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文件?我不想调用子进程使用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天全站免登陆