zoukankan      html  css  js  c++  java
  • emmm......就当练习了系列17

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

    import os
    import sys

    def get_file_size(files_list, size=0):
      for file in files_list:
        if not os.path.isfile(file):
          files_list = os.listdir(file)
          if len(files_list) == 0:
            size += 0
          else:
            return get_file_size(files_list, size)
        else:
          size += os.path.getsize(file)
      return print(size)


    file_dir = sys.argv[1]
    file_list = os.listdir(file_dir)
    get_file_size(file_list)


    2、

    随机验证码

    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))
        res+=random.choice([s1,s2])
      return res

    print(make_code(6))

    模拟下载以及打印进度条

    import time


    def progress(percent):
      if percent > 1:
        percent = 1
      res = int(50 * percent) * '#'
      print(' [%-50s] %d%%' % (res, int(100 * percent)), end='')

    recv_size=0
    total_size=1025011

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

    recv_size+=1024              # recv_size=2048

    # 打印进度条
    print(recv_size)
    percent = recv_size / total_size      # 1024 / 333333
    progress(percent)

    文件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)

  • 相关阅读:
    【Leetcode】Insertion Sort List JAVA实现
    【Leetcode】Sort List JAVA实现
    Maximum Product Subarray JAVA实现
    hadoop2.0中无法启动datanode的问题
    合并排序
    setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式
    postgresql 服务器端编程之hello word
    mac osx get postgresql path
    mac osx install mysql
    django 基于proxy实现用户权限管理
  • 原文地址:https://www.cnblogs.com/lucky-cat233/p/12601913.html
Copyright © 2011-2022 走看看