对于zip,python自带,不需要额外安装库
import zipfiledef unzip(file_path, outpath):## 一下子全部解压# zipfile.ZipFile(file_path).extractall(outpath)##zip_ = zipfile.ZipFile(file_path)names = zip_.namelist()for name in names:zip_.extract(name, outpath)zip_.close()
对与rar压缩包,需要安装库,安装命令如下
sudo apt install unrar
pip install rarfile
import rarfiledef unrar(file_path, outpath):### rarfile.RarFile(file_path).extractall(outpath)##rar_ = rarfile.RarFile(file_path)names = rar_.namelist()for name in names:rar_.extract(name, outpath)rar_.close()
如果觉得《python解压rar zip压缩包》对你有帮助,请点赞、收藏,并留下你的观点哦!