day22 函数整理

# 1.计算 年月日时分秒 于现在之间差了多少 格式化时间
# 现在
# 某一个年月日时分秒  参数
# import time
# def get_time(old_t,fmt = '%Y-%m-%d %H:%M:%S'):
#     struct_t = time.strptime(old_t,fmt)
#     stmp_old = time.mktime(struct_t)
#     stmp_now = time.time()
#     tmp = stmp_now - stmp_old
#     t = time.gmtime(tmp)
#     return(t.tm_year-1970,
#            t.tm_mon - 1,
#            t.tm_mday -1,
#            t.tm_hour -0,
#            t.tm_min -0,
#            t.tm_sec -0)
# div_time = get_time('2018-11-11 17:52:11')
# print(div_time)
# 2.4位的字母+数字验证码
# import random
# def code(n=4):
#     end = ''
#     for i in range(n):
#         num = str(random.randint(0,9))
#         alpha_up = chr(random.randint(65,90))
#         alpha_low = chr(random.randint(97,122))
#         aim = random.choice([num,alpha_up,alpha_low])
#         end += aim
#     return end
# print(code())
# import random#alpha = True生成字母数字验证码,alpha=False生成纯数字验证码
# def code(n=4,alpha = True):
#     end = ''
#     for i in range(n):
#         aim = str(random.randint(0,9))
#         if alpha:
#             alpha_up = chr(random.randint(65,90))
#             alpha_low = chr(random.randint(97,122))
#             aim = random.choice([aim,alpha_up,alpha_low])
#         end += aim
#     return end
# print(code(n=6,alpha=False))
# print(code())
# 4.查看某个目录下的所有文件(包括子文件夹中的)
# import os
# def list_dir(path):
#     lst = os.listdir(path)
#     for name in lst:
#         full_path = os.path.join(path,name)
#         if os.path.isdir(full_path):
#             list_dir(full_path)
#         else:
#             print(full_path)
# list_dir('E:\s17')
# 5.计算文件夹的总大小
# import os
# def list_dir(path):
#     lst = os.listdir(path)
#     sum_size = 0
#     for name in lst:
#         full_path = os.path.join(path,name)
#         if os.path.isdir(full_path):
#             ret = list_dir(full_path)  # 'E:\s17\day18\day17_作业讲解'
#             sum_size += ret
#         else:
#             file_size = os.path.getsize(full_path)
#             sum_size += file_size
#     return sum_size
# ret = list_dir(r'E:\s17')
# print(ret)

猜你喜欢

转载自www.cnblogs.com/pythonz/p/9960009.html