• day22 作业


    1 统计文件夹大小

    def get_filesize(file_path):
        count = 0
        res=None
        files_sum = os.listdir(file_path)
        for files in files_sum:
            new_files = os.path.join(file_path,files)
            if os.path.isdir(new_files):
                res= get_filesize(new_files)
            elif os.path.isfile(new_files):
                size = os.path.getsize(new_files)
                count+=size
        if res==None:
            return count
        elif res>0:
            return count+res
    res = get_filesize(path)
    print(res)
    

    2 模拟下载进度条

    def progress(percent):
        if percent>1:
            percent=1
        str_sap = int(percent*50)*'#'
        print(("
    [%-50s] %s%%")%(str_sap,int(percent*100)),end="")
    recv_size = 0
    total_size = 1024
    while recv_size<total_size:
        recv_size+=10
        import time
        time.sleep(0.1)
        percent = recv_size/total_size
        progress(percent)
    

    3 copy

    import sys
    src_file=sys.argv[1]
    dst_file=sys.argv[2]
    
    with open(r'%s' %src_file,mode='rb') as read_f,
        open(r'%s' %dst_file,mode='wb') as write_f:
        for line in read_f:
            write_f.write(line)
    

    4 验证码

    import random
    def make_code(size):
        str0 = ""
        for i in range(size):
            str1 = chr(random.randint(65,90))
            str2 = chr(random.randint(97,122))
            num = str(random.randint(0,9))
            str0 += random.choice([str1,str2,num])
        return str0
    print(make_code(10))
    
  • 相关阅读:
    英语八级之路
    ASP.NET MVC 简易在线书店
    MySql 笔记
    自定义函数标签(JSTL)
    自定义标签(JSTL)
    Xml读取异常--Invalid byte 1 of 1-byte UTF-8 sequence
    JSTL核心标签库
    JSTL简介
    修改Servlet模板
    获取GET/POST提交的数据,并处理中文问题
  • 原文地址:https://www.cnblogs.com/hz2lxt/p/12601347.html
Copyright © 2020-2023  润新知