本文实例讲述了python下载文件时显示下载进度的方法。分享给大家供大家参考。具体分析如下:
将这段代码放入你的脚本中,类似:urllib.urlretrieve(getFile, saveFile, reporthook=report)
第三个参数如下面的函数定义report,urlretrieve下载文件时会实时回调report函数,显示下载进度
def report(count, blockSize, totalSize):
percent = int(count*blockSize*100/totalSize)
sys.stdout.write("\r%d%%" % percent + ' complete')
sys.stdout.flush()
sys.stdout.write('\rFetching ' + name + '...\n')
urllib.urlretrieve(getFile, saveFile, reporthook=report)
sys.stdout.write("\rDownload complete, saved as %s" % (fileName) + '\n\n')
sys.stdout.flush()
希望本文所述对大家的Python程序设计有所帮助。
最后
以上就是善良招牌最近收集整理的关于python下载文件时显示下载进度的方法的全部内容,更多相关python下载文件时显示下载进度内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复