3.30作业

# 1、检索文件夹大小的程序,要求执行方式如下
# python3.8 run.py
# import os
# import sys
#
# path = os.path.dirname(__file__)
# size = 0
# def get_dir_size(path):
# for line in os.listdir(path):
# path2 = os.path.join(path, line)
# if os.path.isfile(path2):
# global size
# size += os.path.getsize(path2)
# else:
# get_dir_size(path2)
# return size
#
#
# res=get_dir_size(path)
# print(res)

# 文件夹
# 2、明天上午日考:随机验证码、模拟下载以及打印进度条、文件copy脚本
# 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=1000000
while recv_size<total_size:
time.sleep(0.01)
recv_size+=1024
percent=recv_size/total_size
progress(percent)


# 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)











原文地址:https://www.cnblogs.com/chenyoupan/p/12601291.html