Home > Backend Development > Python Tutorial > Python file download and progress bar

Python file download and progress bar

大家讲道理
Release: 2016-11-09 10:40:02
Original
2142 people have browsed it

Demo downloads an mp3 file from a specified url and displays the download progress percentage during the download process

#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)
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template