zoukankan      html  css  js  c++  java
  • re模块, 打印进度条,subprocess模块, 产生随机号码,

    re模块

    import time
    
    def make_progress(percent,width=50):
        if percent > 1:
            percent=1
        show_str=('[%%-%ds]' % width) % (int(percent * width) * '#')
        print('
    %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
  • 相关阅读:
    Spring中的一些常用接口
    ApplicationContextAware的作用
    用spring的 InitializingBean 的 afterPropertiesSet 来初始化
    虚拟机扩容(/dev/mapper/centos-root 空间不足)
    AJAX
    Git
    jQuery
    JS
    JS
    jQuery
  • 原文地址:https://www.cnblogs.com/xiejintao0914/p/9225108.html
Copyright © 2011-2022 走看看