第9章 文件压缩

#文件压缩
import zipfile,os
os.chdir('E:\\04.AutomationProject\\PracticePython\\noteBasic')
# print(os.listdir())
exampleZip = zipfile.ZipFile('example.zip')
print(exampleZip.namelist())
spamInfo =exampleZip.getinfo('01.文件操作.txt')
print(spamInfo.file_size)#压缩前的大小
print(spamInfo.compress_size)#压缩后的大小
print('Compressed file is %sx smaller!' % (round(spamInfo.file_size / spamInfo.compress_size, 2)))#压缩比例
exampleZip.close()

猜你喜欢

转载自blog.csdn.net/baidu_27361307/article/details/80826213