演示从指定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)