[python]代码库
#!/usr/bin/env python
# encoding: utf-8
'''
python可视化进度条
'''
import time
class progress:
def __init__(self):
self.scale = 50
def hello(self):
return self
def run(self):
'''
The program entry
'''
print('执行开始...'.center(self.scale // 2, '-'))
start = time.perf_counter()
for i in range(self.scale + 1):
a = '*' * i
b = '.' * (self.scale - i)
c = (i / self.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(self.scale // 2, '-'))
if __name__ == '__main__':
progress().hello().run()
[代码运行效果截图]