hello world

python3编写的类似于linux下的进度条

废话不多说,直接上代码

#encoding: utf-8

import time

def progress(percent,width=50):
    if percent > 1 :
        percent = 1
    show_str = (('[%%-%ds]' %width) %(int(percent * width) * '#'))
    print('\r%s %d%%' % (show_str,int(percent * 100)),end = '')
    
i=0
max=100
while i < 1 :
    i += 0.01
    percent=i / max
    progress(i,100)
    time.sleep(0.1)
    

  效果图:

[#########################################                                                           ] 41%

posted @ 2019-12-17 13:58  浩天四哥  阅读(285)  评论(0)    收藏  举报