python下載文件時(shí)顯示下載進(jìn)度的方法
來(lái)源:易賢網(wǎng) 閱讀:3267 次 日期:2015-04-20 10:40:55
溫馨提示:易賢網(wǎng)小編為您整理了“python下載文件時(shí)顯示下載進(jìn)度的方法”,方便廣大網(wǎng)友查閱!

具體分析如下:

將這段代碼放入你的腳本中,類(lèi)似: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()

更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

更多信息請(qǐng)查看技術(shù)文章
易賢網(wǎng)手機(jī)網(wǎng)站地址:python下載文件時(shí)顯示下載進(jìn)度的方法
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn)

版權(quán)所有:易賢網(wǎng)