python在控制台输出进度条的方法
本文实例讲述了python在控制台输出进度条的方法。分享给大家供大家参考。具体实现方法如下:
进度条效果如下所示:
|#############################---------------------| 59percentdone
代码如下:
classProgressBar(): def__init__(self,width=50): self.pointer=0 self.width=width def__call__(self,x): #xinpercent self.pointer=int(self.width*(x/100.0)) return"|"+"#"*self.pointer+"-"*(self.width-self.pointer)+\ "|\n%dpercentdone"%int(x)
Testfunction(forwindowssystem,change"clear"into"CLS"):
if__name__=='__main__':
importtime,os
pb=ProgressBar()
foriinrange(101):
os.system('clear')
printpb(i)
time.sleep(0.1)
希望本文所述对大家的Python程序设计有所帮助。
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志