进度条打印函数

进度条打印:

import time
def progress(percent,width=30):
    text=('\r[%%-%ds]'%width)%('x'*int(percent*width))
    text=text+'%3s%%'
    text=text%(round(percent*100))
    print(text,end='')

file_size=10240
cur_size=0
while True:
    cur_size+=1024
    progress(cur_size/file_size)
    time.sleep(0.4)
    if cur_size>=file_size:
        time.sleep(0.5)
        print('\n\nfinish')
        break

猜你喜欢

转载自www.cnblogs.com/oldboy2019/p/10802720.html