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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Try the pyunpack
package:
from pyunpack import Archive
Archive('a.zip').extractall('/path/to')
回答2:
Late, but I wasn't satisfied with any of the answers.
pip install patool
import patoolib
patoolib.extract_archive("foo_bar.rar", outdir=".")
Works on Windows and linux without any other libraries needed.
回答3:
A good package for it is rarfile
:
Infos and docs here :
https://pypi.python.org/pypi/rarfile/
https://rarfile.readthedocs.org/en/latest/api.html
回答4:
- How to unzip a file with Python 2.4?
- https://pypi.python.org/pypi/rarfile/