extract 7z file using python 3 [duplicate]

随声附和 提交于 2020-02-03 08:05:26

问题


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:

I thought it would work like the zipfile package:

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

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.

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.

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.

Here is the properties from the 7z file:


回答1:


What about trying this?:

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


来源:https://stackoverflow.com/questions/44132184/extract-7z-file-using-python-3

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