re模块, 打印进度条,subprocess模块, 产生随机号码,

re模块

import time

def make_progress(percent,width=50):
    if percent > 1:
        percent=1
    show_str=('[%%-%ds]' % width) % (int(percent * width) * '#')
    print('\r%s %s%%' %(show_str,int(percent * 100)),end='')

total_size=1025
recv_size=0
while recv_size < total_size:
    time.sleep(0.1) # 模拟经过了0.5的网络延迟下载了1024个字节
    recv_size+=1024
    # 调用打印进度条的功能去打印进度条
    percent=recv_size / total_size
    make_progress(percent)
打印进度条

subprocess模块

产生随机号码

def make_code(size=7):
    res = ''
    for i in range(size):
        # 循环一次则得到一个随机字符(字母/数字)
        s = chr(random.randint(65, 90))
        num = str(random.randint(0, 9))
        res += random.choice([s, num])
    return res


res=make_code()
print(res)
View Code

猜你喜欢

转载自www.cnblogs.com/xiejintao0914/p/9225108.html