How can unrar a file with python

2 8 picture 2 8 · Jul 12, 2013 · Viewed 63.8k times · Source

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?

Answer

Amir picture Amir · Oct 3, 2014

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.