from time import sleep
# 容器大小
total =999999999# 初始读取值为0
already =0while already < total:# 一次读取
once =12345679# 已经读取
already += once
# 打印进度
length =int(100* already / total)
sleep(0.1)print('\r%9d/%9d: %100s'%(already, total,('\033[0;7m \033[0m'* length)), end='')
版本2
import random
# 容器大小
container =[1000+ random.randint(-9,9)for i inrange(9999999)]
total =sum(container)# 初始读取值为0
already =0while already < total:# 一次读取数
once = container.pop()# 已经读取
already += once
# 打印进度if already %1000== total %1000:
a =int(100* already / total)print('\r%10d/%10d: %100s'%(already, total,('\033[0;7m \033[0m'* a)), end='')
第三方库:tqdm
from time import sleep
from tqdm import tqdm, trange
for i in trange(100):
sleep(0.01)
pbar = tqdm(list('abcde'))for char in pbar:
sleep(0.5)
pbar.set_description("%s"% char)