如何用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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:40:41  来源:igfitidea点击:

How can unrar a file with python

pythonpython-2.7unzipunrar

提问by 2 8

I can to unzip a file if file is a .zipand 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

Try the pyunpackpackage:

试试这个pyunpack包:

from pyunpack import Archive
Archive('a.zip').extractall('/path/to')

回答by Romibuzi

回答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,无需任何其他库。