简单版:
import time
for x in range(100):
print("\r"+x*">",end='')
time.sleep(0.1)
升级版:
import time
for x in range(50):
print('\r'+ '|' +x*'>'+ (50-x)*' '+'|'+str(x)+'%',end='')
time.sleep(0.5)
开发版:
import sys
import time
def processBar(num, total):
rate = num / total
rate_num = int(rate * 101)
if rate_num == 100:
r = '\r%s>%d%%\n' % ('=' * rate_num, rate_num,)
else:
r = '\r%s>%d%%' % ('=' * rate_num, rate_num,)
sys.stdout.write(r)
for i in range(101):
time.sleep(0.1)
processBar(i,101)
正规版:
通过使用Tqdm模块,他是一个扩展性强的进度条工具库,提供了许多接口,下面演示一个简单的用法
from time import sleep from tqdm import tqdm for i in tqdm(range(0,500)): sleep(0.01)
效果