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

Python file download and progress bar

大家讲道理
大家讲道理Original
2016-11-09 10:40:022195browse

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)


Statement:
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
Previous article:Python connects to OracleNext article:Python connects to Oracle