欢迎来到山村网

python下载文件时显示下载进度的方法

2019-03-02 11:57:51浏览:480 来源:山村网   
核心摘要:具体分析如下:将这段代码放入你的脚本中,类似:urllib.urlretrieve(getFile, saveFile, reporthook=report)第三个参数如下面的

具体分析如下:

将这段代码放入你的脚本中,类似:urllib.urlretrieve(getFile, saveFile, reporthook=report)

第三个参数如下面的函数定义report,urlretrieve下载文件时会实时回调report函数,显示下载进度

1 2 3 4 5 6 7 8 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) + 'nn') sys.stdout.flush()
(责任编辑:豆豆)
下一篇:

python连接远程ftp服务器并列出目录下文件的方法

上一篇:

用Python实现通过哈希算法检测图片重复的教程

  • 信息二维码

    手机看新闻

  • 分享到
打赏
免责声明
• 
本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们 xfptx@outlook.com