文本进度条 简单的开始
1
2
3
4
5
6
7
8
9
10
11
|
#TextProBarV1.py
import time
scale = 10
print("------执行开始------")
for i in range(scale+1):
a = '*' * i
b = '.' * (scale - i)
c = (i/scale)*100
print("{:^3.0f}%[{}->{}]".format(c,a,b))
time.sleep(0.1)
print("------执行结束------")
|
文本进度条 单行动态刷新
1
2
3
4
5
|
#TextProBarV2.py
import time
for i in range(101):
print("\r{:3}%".format(i), end="")
time.sleep(0.1)
|
文本进度条 实例完整效果
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#TextProBarV3.py
import time
scale = 50
print("执行开始".center(scale//2, "-"))
start = time.perf_counter()
for i in range(scale+1):
a = '*' * i
b = '.' * (scale - i)
c = (i/scale)*100
dur = time.perf_counter() - start
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur),end='')
time.sleep(0.1)
print("\n"+"执行结束".center(scale//2,'-'))
|
参考资料:Python语言程序设计基础(第2版)》嵩天、礼欣、黄天羽著,高等教育出版社,2017.2(讲授Python 3版本)
视频课程
Python3菜鸟教程
Python官方手册