如何用python解压文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17614467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can unrar a file with python
提问by 2 8
I can to unzip a file if file is a .zip
and unrar file if my file type is .rar
.
How i can do this work with python 2.7?
如果文件是一个.zip
,我可以解压缩一个文件,如果我的文件类型是.rar
. 我如何使用 python 2.7 完成这项工作?
采纳答案by Irakli Darbuashvili
回答by Roman Pekar
回答by Romibuzi
A good package for it is rarfile
:
一个很好的包是rarfile
:
Infos and docs here :
信息和文档在这里:
https://pypi.python.org/pypi/rarfile/
https://pypi.python.org/pypi/rarfile/
回答by Amir
Late, but I wasn't satisfied with any of the answers.
迟到了,但我对任何答案都不满意。
pip install patool
import patoolib
patoolib.extract_archive("foo_bar.rar", outdir="path here")
Works on Windows and linux without any other libraries needed.
适用于 Windows 和 linux,无需任何其他库。