[Python]-tools

Python进度条

# -*- coding: UTF-8 -*-
# from __future__ import division

import sys
import math
import time

def prcc(fas, frss):     #(文件的总大小,接收的文件大小)
    wight = 50      #控制进度条的总长度
    t = frss / fas  #计算接收文件的大小与文件总大小之间的百分比
    wt = int(math.ceil(wight * t))  #通过百分比来控制#号的个数
    tb = math.ceil(t*100)       #接收文件百分比
    r = '  %d' %tb + '%	' + '[' + '='*wt + ' '*(wight - wt) + ']' + '
'   #定义输出的内容格式
    sys.stdout.write(r)     #标准输出
    sys.stdout.flush()  #强制刷新

for i in range(0,100000,1024):  #模拟文件的传输
    time.sleep(0.2)
    prcc(100000,i)
原文地址:https://www.cnblogs.com/chenwz/p/7850241.html