示範從指定url下載一個mp3文件,並在下載過程中顯示下載進度百分比
#encoding=utf-8 import urllib import sys def cbk(a,b,c): per = 100.0*a*b/c if per >100: per=100 def cls(str): return '\r'*len(str) out='%.2f%%'%per sys.stdout.write(u'下载进度:') sys.stdout.write(out) sys.stdout.write(cls(out)) url="" urllib.urlretrieve(url,'download_123.mp3',cbk)