标签:origin read operator 程序 ade 模拟 sum ora white
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 i 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(‘\r[%-50s] %d%%‘ % (res, int(100 * percent)), end=‘‘)
标签:origin read operator 程序 ade 模拟 sum ora white
原文地址:https://www.cnblogs.com/bailongcaptain/p/12601897.html