标签:指定 users getc lan zip import 多个 imp lis
压缩备份多个文件import os
import shutil
os.getcwd()
‘C:\\Users\\coop‘
# 创建
import zipfile
my_zip = zipfile.ZipFile(‘coop.zip‘, ‘w‘) # 创建对象,写入文件
# my_zip.write
my_zip.write(‘怎样压缩备份多个文件.ipynb‘,compress_type = zipfile.ZIP_DEFLATED)
my_zip.write(‘面向对象的三大特征.ipynb‘, compress_type = zipfile.ZIP_DEFLATED)
my_zip.close()
#查看
coop = zipfile.ZipFile(‘coop.zip‘)
coop.namelist()
[‘怎样压缩备份多个文件.ipynb‘, ‘面向对象的三大特征.ipynb‘]
coop.getinfo(‘怎样压缩备份多个文件.ipynb‘)
<ZipInfo filename=‘怎样压缩备份多个文件.ipynb‘ compress_type=deflate filemode=‘-rw-rw-rw-‘ file_size=7132 compress_size=1528>
coop.close()
shutil.copy(‘coop.zip‘, ‘coop_1.zip‘)
‘coop_1.zip‘
# 解压缩
coop = zipfile.ZipFile(‘coop_1.zip‘)
coop.extractall(‘D:\python全站‘) # 括号里面的参数可选,可以使当前目录,也可以指定目录
coop.close()
标签:指定 users getc lan zip import 多个 imp lis
原文地址:http://blog.51cto.com/13118411/2137382