python下載文件時顯示下載進度的方法
本文實例講述了python下載文件時顯示下載進度的方法。分享給大家供大家參考。具體分析如下:
將這段代碼放入你的腳本中,類似:urllib.urlretrieve(getFile, saveFile, reporthook=report)
第三個參數(shù)如下面的函數(shù)定義report,urlretrieve下載文件時會實時回調(diào)report函數(shù),顯示下載進度
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程序設(shè)計有所幫助。
相關(guān)文章
python基礎(chǔ)教程之python消息摘要算法使用示例
這篇文章主要介紹了python中的消息摘要算法使用示例,需要的朋友可以參考下2014-02-02
Python使用DPKT實現(xiàn)分析數(shù)據(jù)包
dpkt項目是一個Python模塊,主要用于對網(wǎng)絡(luò)數(shù)據(jù)包進行解析和操作,z這篇文章主要為大家介紹了python如何利用DPKT實現(xiàn)分析數(shù)據(jù)包,有需要的可以參考下2023-10-10
Django 全局的static和templates的使用詳解
這篇文章主要介紹了Django 全局的static和templates的使用詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-07-07
使用Python的Django框架結(jié)合jQuery實現(xiàn)AJAX購物車頁面
這篇文章主要介紹了使用Python的Django框架結(jié)合jQuery實現(xiàn)AJAX購物車頁面的方法,示例基于Django中構(gòu)建好的JSON格式的RESTful API需要的朋友可以參考下2016-04-04

