第一种方法:
import sys import time def view_bar(num): r = ‘\r[%s%s] %d%%‘ % ("="*num, " "*(100-num), num) sys.stdout.write(r) sys.stdout.flush() if __name__ == ‘__main__‘: for i in xrange(0,101): time.sleep(0.1) view_bar(i)
效果如下:
[[email protected] ~/Documents/python/learning]$ python test.py
[============================= ] 78%
时间: 2024-10-06 11:09:22