shutil模块

shutil模块是高层次的文件接口,除了包含文件和目录的操作函数外,还包含里压缩包的创建和解压,支持的格式通过get_archive_formats()函数查询

In [57]: shutil.get_archive_formats()
Out[57]:
[('bztar', "bzip2'ed tar-file"),
('gztar', "gzip'ed tar-file"),
('tar', 'uncompressed tar file'),
('zip', 'ZIP file')]

1、创建压缩包

shutil.make_archive('backup','gztar') 

backup压缩包的名字,gztar压缩格式,默认压缩路径为当前路径,也可以指定路径

2、解压缩

shutil.unpack_archive(压缩包名字,解压保存的路径,压缩包的格式(一般不用写))

原文地址:https://www.cnblogs.com/superniao/p/10547726.html