要实现控制台的监控,达到能完成控制台进度自动刷新python方法源码。这是我自己测试用的,能达到我预期的要求,应该还能再精进一些。有需要类似操作的朋友可以自己再把代码改一下再用。
下边的python方法中,只需要用python sys和python time时间模块中的方法,还是比较简单的。
import sys
import time
# Output example: [======= ] 75%
# width defines bar width
# percent defines current percentage
def progress(width, percent):
print "%s %d%%\r" % (('%%-%ds' % width) % (width * percent / 100 * '='), percent),
if percent >= 100:
sys.stdout.flush()
# Simulate doing something ...
for i in xrange(100):
progress(50, (i + 1))
time.sleep(0.01) # Slow it down for demo
#www.iplaypy.com
玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/code/scripts-shell/ss2342.html
相关文章 Recommend