python在控制台输出进度条的方法,python进度条
python在控制台输出进度条的方法,python进度条
本文实例讲述了python在控制台输出进度条的方法。分享给大家供大家参考。具体实现方法如下:
进度条效果如下所示:
|#############################---------------------| 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)+\ "|\n %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程序设计有所帮助。
相关内容
- Python中map和列表推导效率比较实例分析,python实例分析
- Python求两个文本文件以行为单位的交集、并集与差集的
- Python操作串口的方法,python操作串口
- Python合并两个字典的常用方法与效率比较,python合并
- Python使用urllib2模块实现断点续传下载的方法,pythonur
- Python实现的使用telnet登陆聊天室实例,pythontelnet
- 在Python的struct模块中进行数据格式转换的方法,python
- Python基于Tkinter的HelloWorld入门实例,tkinterhelloworld
- Python基于Tkinter实现的记事本实例,pythontkinter实例
- Python实现的彩票机选器实例,python彩票机
评论关闭