import sys
import time
def view_bar(num, total):
rate = num / total
rate_num = int(rate * 100)
r = '\r[%s%s]%d%% ' % ("="*num, " "*(100-num), num, )
sys.stdout.write(r)
sys.stdout.flush()
#在python中,输出stdout(标准输出)可以使用sys.stdout.write
if __name__ == '__main__':
for i in range(0, 101):
time.sleep(0.1)
view_bar(i, 100)
==============================================================================
import os,sys,string
import time
def view_bar(num=1, sum=100, bar_word=":"):
rate = float(num) / float(sum)
rate_num = int(rate * 100)
print '\r%d%% :' %(rate_num),
for i in range(0, num):
os.write(1, bar_word)
sys.stdout.flush()
if __name__ == '__main__':
for i in range(0, 101):
time.sleep(0.1)
view_bar(i, 100)
==========================================================================
import sys, time
for i in range(5):
sys.stdout.write(' ' * 10 + '\r')
sys.stdout.flush()
print i
sys.stdout.write(str(i) * (5 - i) + '\r')
sys.stdout.flush()
time.sleep(1)
==========================================================================
import time
import progressbar
p = progressbar.ProgressBar()
N = 1000
for i in p(range(N)):
time.sleep(0.01)
==============================================================================
import time
import progressbar
p = progressbar.ProgressBar()
N = 1000
p.start(N)
for i in range(N):
time.sleep(0.01)
p.update(i+1)
p.finish()
=================================================================================
import time
import progressbar
bar = progressbar.ProgressBar(widgets=[
' [', progressbar.Timer(), '] ',
progressbar.Percentage(),
' (', progressbar.ETA(), ') ',
])
for i in bar(range(1000)):
time.sleep(0.01)
#说明如下
'Timer', # 计时器
'ETA', # 预计剩余时间
'AbsoluteETA', # 预计结束的绝对时间,耗时很长时使用较方便
'Percentage', # 百分比进度,30%
'SimpleProgress', # 计数进度,300/1000
'Counter', # 单纯计数
'Bar' # “#”号进度条
====================================================================================
import time
import progressbar
bar =
progressbar.ProgressBar(widgets=[
progressbar.Percentage(),
' (', progressbar.SimpleProgress(), ') ',
' (', progressbar.AbsoluteETA(), ') ',])
for i in bar(range(1000)):
time.sleep(0.01)
阅读(1076) | 评论(0) | 转发(0) |