# 加密 ''' md5 = hashlib.md5() md5.update('how to use md5 in python hashlib?') #字节才可以 print md5.hexdigest() ''' 进度条 =========知识储备========== 进度条的效果 [# ] [## ] [### ] [#### ] 指定宽度 print('[%-15s]' %'#') print('[%-15s]' %'##') print('[%-15s]' %'###') print('[%-15s]' %(15*'#')) 打印% print('%s%%' %(100)) #第二个%号代表取消第一个%的特殊意义 可传参来控制宽度 print('[%%-%ds]' %50) #[%-50s] print(('[%%-%ds]' %50) %'#') print(('[%%-%ds]' %50) %'##') print(('[%%-%ds]' %50) %'###') =========实现打印进度条函数========== import sys import time def progress(percent,width=50): if percent >= 1: percent=1 show_str = ('%%-%ds' % width) % (int(width*percent)*'*') # print(' %s %d%%' %(show_str, int(100*percent)), end='') print(' %s %d%%' %(show_str, int(100*percent))) # progress(8,5) #=========应用========== data_size=1025 recv_size=0 while recv_size < data_size: time.sleep(1) #模拟数据的传输延迟 recv_size+=1024 #每次收1024 percent=recv_size/data_size #接收的比例 progress(percent,width=50) #进度条的宽度70 import sys import time def progress(percent,width=50): if percent >= 1: percent=1 show_str = ('%%-%ds' % width) % (int(width*percent)*'*') print(' %s %d%%' %(show_str, int(100*percent)), end='') # print(' %s %d%%' %(show_str, int(100*percent))) #=========应用========== data_size=1888 recv_size=0 while recv_size < data_size: recv_size+=1024 #每次收1024 percent=recv_size/data_size #接收的比例 if percent >= 1: percent=1 show_str = ('%%-%ds' % 50) % (int(50*percent)*'*') print(' %s %d%%' %(show_str, int(100*percent)), end='')