欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python下載文件時(shí)顯示下載進(jìn)度的方法

 更新時(shí)間:2015年04月02日 09:52:12   作者:令狐不聰  
這篇文章主要介紹了python下載文件時(shí)顯示下載進(jìn)度的方法,涉及Python文件操作的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了python下載文件時(shí)顯示下載進(jìn)度的方法。分享給大家供大家參考。具體分析如下:

將這段代碼放入你的腳本中,類似:urllib.urlretrieve(getFile, saveFile, reporthook=report)

第三個(gè)參數(shù)如下面的函數(shù)定義report,urlretrieve下載文件時(shí)會(huì)實(shí)時(shí)回調(diào)report函數(shù),顯示下載進(jìn)度

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()

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論