zoukankan      html  css  js  c++  java
  • 3-30作业

    # 1、检索文件夹大小的程序,要求执行方式如下python3.8  run.py文件夹
    import sys,os
    src = sys.argv[1]
    res = 0
    
    def size_of_file(file):
        global res
        for file1 in os.listdir(r'%s'%file):
            path = os.path.join(file,file1)
            print(path)
            if os.path.isfile(path):
                res += os.path.getsize(src)
            else:
                size_of_file(path)
    
    if os.path.isfile(r'%s'%src):
        res = os.path.getsize(src)
    else:
        size_of_file(src)
    print(res)
    
    

    # 2、明天上午日考:随机验证码、模拟下载以及打印进度条、文件copy脚本
    (一)随机验证码
     1 import random
     2 
     3 def make_code(size):
     4     res=''
     5     for x in range(size):
     6         l1=chr(random.randint(65,90))
     7         l2=str(random.randint(0,9))
     8         res+=random.choice([l1,l2])
     9     return res
    10 print(make_code(8))
    
    
    (二)模拟下载及打印进度条
    import time
    def progress(percent):
        if percent>1:
            percent=1
        res = int(66 * percent) * '$'
        print('
    [%-50s] %d%%' % (res, int(100 * percent)), end='')
    
    recv_size=0
    data_size=102411
    
    while recv_size < data_size:
        time.sleep(0.08) #模拟数据的传输延迟时间
        recv_size+=1024 #下载了1024个字节的数据
    
        percent=recv_size/data_size #接收的比例
        progress(percent)                     

      

    (三)文件copy脚本

    import sys
    import os
    
    file_path = sys.argv
    def copy(src, dst):
        name = os.path.basename(src)
        print(name)
        if os.path.isfile(dst):
            print('目标路径不是个文件夹')
            return None
        dst = os.path.join(dst,name)
        with open(src,'rb') as f1,
            open(dst,'wb') as f2:
            f2.write(f1.read())
    
    copy(file_path[1],file_path[2])
  • 相关阅读:
    面试开发需要准备的
    多线程 多进程
    TCP/IP协议学习
    深信服算法岗实习面试经验
    TZOJ4777: 方格取数
    Python 基于 NLP 的文本分类
    mac os 使用记录
    字节跳动游戏开发岗题目
    mac进行acm(C/C++)编程
    常用的正则表达式(转)
  • 原文地址:https://www.cnblogs.com/2722127842qq-123/p/12600274.html
Copyright © 2011-2022 走看看