零碎知识
print() print(......,end='\n') ****print 自带end=‘\n’,默认为换行,可以修改end=‘ ’的值。使print不换行
1 打印进度条 2 # print('[ ]') 3 # print('[## ]') 4 # print('[### ]') 5 # print('[#### ]') 6 # print('[##### ]') 7 8 9 # print('[%-50s]' %'#') 10 # print('[%-50s]' %'##') 11 # print('[%-50s]' %'###') 12 13 14 # 第一个%是取消第二个%号的特殊意义的 15 # num=30 16 # print('%s%%' %num) 17 18 19 # width=30 20 # print(('[%%-%ds]' %width) %'#') 21 # print(('[%%-%ds]' %width) %'##') 22 # print(('[%%-%ds]' %width) %'###') 23 24 25 26 ####################################### 27 import time 28 recv_size = 0 29 total_size = 100000 30 31 def progress(percent,width=50): 32 if percent > 1: 33 percent =1 34 show_str = ('[%%-%ds]' %width) %(int(width*percent) * '#') 35 print('\r%s %d%%' %(show_str,int(100*percent)),end = '') 36 37 while recv_size < total_size: 38 time.sleep(0.2) 39 recv_size += 8096 40 percent = recv_size / total_size 41 progress(percent)