zoukankan      html  css  js  c++  java
  • time与datetime模块 、random模块 、os模块 、sys模块 练习

    # 今日作业:
    # 1、检索文件夹大小的程序,要求执行方式如下
    # python3.8 run.py 文件夹
    # 2、明天上午日考:随机验证码、模拟下载以及打印进度条、文件copy脚本
    # 随机验证码
    '''
    import random
    def verification_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(verification_code(6))
    '''
    # 模拟下载以及打印进度条
    '''
    import time

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

    size=356789
    r_size=0
    while r_size < size:
    r_size += 2048
    time.sleep(0.01)
    percent=r_size / size
    progress(percent)
    '''
    # 文件copy脚本
    '''
    import shutil
    def copy(old_txt, new_txt):
    shutil.copyfile(old_txt, new_txt)
    '''
    # 检索文件夹大小的程序,要求执行方式如下
    '''
    import os
    def sizes(file):
    if os.path.isfile(file):
    size = os.path.getsize(file)
    print(size)

    sizes(r'C:UsersdellDesktoppython14期day22代码作业.py')
    '''
  • 相关阅读:
    编写可维护的JavaScript代码(部分)
    Canvas
    初识ES6
    vue.js入门上
    ASP.NET中的物理路径与虚拟路径
    慎用标签选择器
    PHP服务器负载判断
    mac下安装redis
    mac安装memcache
    MySQL定时检查是否宕机并邮件通知
  • 原文地址:https://www.cnblogs.com/0B0S/p/12601317.html
Copyright © 2011-2022 走看看