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?
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.
Try the pyunpack
package:
from pyunpack import Archive
Archive('a.zip').extractall('/path/to')
After some deep diving, here are my findings:
patool
is application that provides uniform command line as wrapper to other external compression applications. Natively, it can only deal with TAR, ZIP, BZIP2 and GZIP without needing external support.pyunpack
is Python library that can only deal with zip natively but provides interface to patool
. With this in mind, following things worked for me:
pip install patool pyunpack
Then to use it,
import pyunpack
pyunpack.Archive(archive_file).extractall(extract_dir)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.