进度条效果如下所示:
|#############################---------------------| 59 percent done
代码如下:
class ProgressBar(): def __init__(self, width=50): self.pointer = 0 self.width = width def __call__(self,x): # x in percent self.pointer = int(self.width*(x/100.0)) return "|" + "#"*self.pointer + "-"*(self.width-self.pointer)+ "| %d percent done" % int(x)
Test function (for windows system, change "clear" into "CLS"):
if __name__ == '__main__': import time, os pb = ProgressBar() for i in range(101): os.system('clear') print pb(i) time.sleep(0.1)
希望本文所述对大家的Python程序设计有所帮助。
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com