监控ZIP文件提取Python [英] Monitor ZIP File Extraction Python
本文介绍了监控ZIP文件提取Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要解压缩.ZIP存档.我已经知道如何解压缩它,但是它是一个巨大的文件,需要一些时间才能解压缩.我如何打印提取完成的百分比?我想要这样的东西:
I need to unzip a .ZIP archive. I already know how to unzip it, but it is a huge file and takes some time to extract. How would I print the percentage complete for the extraction? I would like something like this:
Extracting File
1% Complete
2% Complete
etc, etc
推荐答案
以下是您可以优化的示例:
here an example that you can start with, it's not optimized:
import zipfile
zf = zipfile.ZipFile('test.zip')
uncompress_size = sum((file.file_size for file in zf.infolist()))
extracted_size = 0
for file in zf.infolist():
extracted_size += file.file_size
print "%s %%" % (extracted_size * 100/uncompress_size)
zf.extract(file)
为了使其更美观,请在打印时执行以下操作:
to make it more beautiful do this when printing:
print "%s %%\r" % (extracted_size * 100/uncompress_size),
这篇关于监控ZIP文件提取Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文