最近做一個惡搞向的小程序,就是一系列初始化才能進入到SCP基金會內(nèi)部網(wǎng)絡(luò)神馬的,中間需要使用到進度條的東西,看來看去根據(jù)大神們的代碼get到了,所以自己寫了一個類似demo的東西,放在這里備用。
import sys,time
class Process_bar:
data=0; #當(dāng)前進度
total=100; #總進度
title="Undefine"; #顯示進度標(biāo)題
def run(self):
t_str=self.title
if(len(self.title)>20):
t_str=self.title[0:20]+'...'
#這些是對進度標(biāo)題的限制,超過20個的只能顯示前20個字符的縮寫
while(self.data < self.total ):
self.data=self.data+1 #本來應(yīng)該是獲得當(dāng)前時間的進度數(shù)據(jù)
percent=int(((self.data / self.total)*100)//1)
str='='*percent+'_'*(100-percent)
sys.stdout.write('\r'+t_str+' ['+str+']'+' [%s%%]'%(percent))
time.sleep(0.02) #為了體現(xiàn)進度條
sys.stdout.flush()
sys.stdout.write('\n')
#End of function run()
#End of Class Process_bar
#Demo
a=Process_bar()
a.title="正在初始化網(wǎng)絡(luò)……"
a.run()
b=Process_bar()
b.title="How are you Indian Mi fan,do you like mi4i?"
b.run()
#END
這僅僅是一個Demo,后續(xù)還要改編……