def print_progress(total):
    received_size = 0
    current_percent = 0
    while received_size < total:
        new_size = yield
        if int((received_size / total) * 100) > current_percent:
            print("#", end="")
            current_percent = int((received_size / total) * 100)
        received_size += new_size

x = 1000
received_size = 0
progress = print_progress(1000)
progress.__next__()
while x > received_size:
    received_size += 100
    try:
        progress.send(100)
    except StopIteration as e:
        print("[100%]", end="")

 

改进:python sys.stdout.write  实现更好的输出效果

import sys, os
import time
for i in range(100):
    time.sleep(1)
    sys.stdout.write("\r File transfer progress :%2d percent complete!" % i)

 

 http://www.cnblogs.com/hongfei/p/3982259.html

相关文章:

  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2021-12-31
  • 2022-12-23
猜你喜欢
  • 2021-06-18
  • 2021-11-08
  • 2021-10-10
  • 2021-06-11
  • 2021-12-27
相关资源
相似解决方案