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()
  • 相关阅读:
    Java自学笔记(21):【IO】数据流,标准输入输出
    makefile 学习笔记
    tensorflow 环境搭建
    matlab
    【转】MATLAB各种矩阵生成函数
    leetcode刷题收获
    leetcode 15. 3Sum
    STL 记录
    leetcode 服务器环境
    visual studio 2017 使用笔记
  • 原文地址:https://www.cnblogs.com/zhangjinyi97/p/12601759.html
Copyright © 2011-2022 走看看