示例一
import time def show_progress(recv_size, total_size): while recv_size < total_size: time.sleep(0.01) recv_size += 10 percent = recv_size / total_size # 0.5 if percent > 1: percent = 1 strvar = int(percent * 50) * "#" print("\r[%-50s] %d%%" % (strvar, percent * 100), end="") show_progress(0, 1000)
示例二
import time import sys has_send = 0 total = 1000 def show_progress(has, total): rate = float(has) / float(total) rate_num = int(rate * 100) if rate_num != 0: sys.stdout.write("%s%% %s\r" % (rate_num, rate_num * "#")) while has_send < total: time.sleep(0.05) has_send += 10 show_progress(has_send, total)