zoukankan      html  css  js  c++  java
  • Python学习————作业

    今日作业:

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

    python3.8 run.py 文件夹

    import os
    import sys
    
    # path=sys.argv[1]
    size = 0
    
    
    def get_filesize(path):
        files = os.listdir(path)
        for file in files:
            if os.path.isfile(file):
                global size
                size += os.path.getsize(file)
            elif os.path.isdir(file):
                get_filesize(file)
    

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

    随机验证码
    import random
    
    n = random.randint(1, 9)
    
    
    def randomcode(n):
        code = ''
        for i in range(n):
            s1 = chr(random.randint(65, 122))
            s2 = str(random.randint(0, 9))
            s = random.choice([s1, s2])
            code += s
        return code
    
    
    print(randomcode(n))
    
    进度条
    import time
    
    
    def progress(percent, size=100):
        int(percent)
        res = int(percent * size) * '>'
        print('
    [%-100s] %d%%' % (res, 100 * percent), end='')
    
    
    total = 333333
    now_dl = 0
    while now_dl < total:
        now_dl += 1024
        percent = now_dl / total
        time.sleep(0.05)
        if percent > 1:
            percent = 1
        progress(percent)
    
    copy
    import sys
    
    src_file = sys.argv[1]
    dst_file = sys.argv[2]
    
    with open(r'{}'.format(src_file), 'rb') as rf, 
            open(r'{}'.format(dst_file), 'wb') as wf:
        data = rf.read()
        wf.write(data)
    
  • 相关阅读:
    attr 修改IMG src
    64转2
    :eq
    DOM0和D0M2级事件
    c's's透明度
    span标签 宽度无效解决方案
    CSS 点击事件
    input点击后的 默认边框去除
    js
    CSS 的 ID 和 Class 有什么区别,如何正确使用它们。
  • 原文地址:https://www.cnblogs.com/x945669/p/12602110.html
Copyright © 2011-2022 走看看