zoukankan      html  css  js  c++  java
  • python第22天作业

    今日作业:

    1、检索文件夹大小的程序

    要求执行方式如下python3.8 run.py 文件夹

    import os
    import sys
    
    file_list = os.listdir(sys.argv[1])
    
    def file_size(file_list,size = 0):
        for file in file_list:
            if not os.path.isfile(file):
                file_list = os.listdir(file)
                if not file_list:
                    return file_size(file_list,size)
                else:
                    continue
            else:
                size += os.path.getsize(file)
    
    file_size(file_list)
    

    2、明天上午日考:随机验证码、模拟下载以及打印进度条、文件copy脚本

    1、随机验证码

    import random
    def make_code(size=4):
        res=''
        for i in range(size):
            s1=chr(random.randint(65,90))
            s2=str(random.randint(0,9))
            s3=chr(random.randint(97,122))
            print(res)
        return res
    
    print(make_code(6))
    

    2、模拟下载以及打印进度条

    import time
    
    def progress(percent):
        if percent > 1:
            percent = 1
        res = int(50 * percent) * '>'
        print('
     [%-50s] %d%%' % (res,percent*100), end='')
    
    recv_size = 0
    total_size = 33333
    
    while recv_size < total_size:
        time.sleep(0.2)
        recv_size += 1024
        percent = recv_size / total_size    
        progress(percent)
    

    3、文件copy脚本

    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)
    
  • 相关阅读:
    为网站添加图标和收藏夹图标
    常用css入门
    利用反射动态创建对象
    如何用实现.NET的插件机制
    设计模式(18)-Command Pattern
    C#中调用API
    判断一个string是否可以为数字
    080709 阴
    7月9日 多云
    080710 闷热闷热
  • 原文地址:https://www.cnblogs.com/Lance-WJ/p/12601348.html
Copyright © 2011-2022 走看看