zoukankan      html  css  js  c++  java
  • 20.03.30作业

    import sys
    import time
    import os

    1、检索文件夹大小的程序,要求执行方式如下python3.8 run.py 文件夹

    path = sys.argv[1]

    sum = 0
    for line in os.listdir(path):
        path2 = os.path.join(path, line)
        if os.path.isfile(path2):  # 判断这个文件是否存在
           sum += os.path.getsize(path2)
        elif os.path.isdir(path2): # 判断这个目录是否存在
           sum += os.path.getsize(path2)
        else:
            continue
    print(sum)

    文件拷贝脚本

    src_file =sys.argv[1]
    dst_file =sys.argv[2]
    with open(src_file,'r',encoding='utf-8')as r_f,
        open(dst_file,'w',encoding='utf-8')as w_f:
        w_f.write(r_f.read())

    随机验证码

    import random


    def make_code(size=4):
        res = ''
        for in range(size):
            s1 = chr(random.randint(65, 90))
            s2 = str(random.randint(0, 9))
            res += random.choice([s1, s2])
        return res

    模拟下载

    recv_size = 0
    total_size = 1025011

    while recv_size total_size:
        time.sleep(0.01)  # 0.01秒下载了1024个字节的数据

        recv_size += 1024  # recv_size=2048
        print(recv_size)

    进度条打印

    def progress(percent):
        if percent 1:
            percent = 1
        res = int(50 percent) '#'
        print()
  • 相关阅读:
    站立会议(二)
    站立会议(一)
    买书优惠问题
    软件的NABCD----安装部分
    你的灯亮着吗读书笔记(一)
    软件工程概论---环状二维数组最大子数组和
    梦断代码读书笔记(三)
    梦断代码读书笔记(二)
    课程作业3.10
    软件工程作业提交3.06
  • 原文地址:https://www.cnblogs.com/zhangjinyi97/p/12601759.html
Copyright © 2011-2022 走看看