Python【打印进度条】

直接复制即可

版本1
from time import sleep
# 容器大小
total = 999999999
# 初始读取值为0
already = 0
while 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 in range(9999999)]
total = sum(container)
# 初始读取值为0
already = 0
while 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='')

猜你喜欢

转载自blog.csdn.net/Yellow_python/article/details/81298486