python第二十天
python第二十天
shutil模块
import shutil
# shutil.copy2('D:\python_22\day21\lianjia.html',#
# 'D:\python_22\day21\lianjia_bk.html')
# shutil.copytree("outer",
# "outer3",
# ignore=shutil.ignore_patterns("__init__.py","sag"))
# shutil.rmtree("D:\python_22\day21\outer3")
# shutil.move("D:\python_22\day21\day20_bak","D:\python_22\day20", copy_function=shutil.copy2)
# total, used, free = shutil.disk_usage("c:\\")
# print("当前磁盘共: %iGB, 已使用: %iGB, 剩余: %iGB"%(total / 1073741824, used / 1073741824, free / 1073741824))
# shutil.make_archive('outer_z', 'zip','D:\python_22\day21\outer')
# shutil.unpack_archive('outer_z.zip',r'D:\python_22\day21\unzip')
logging模块
# 同时向文件和屏幕上输出 和 乱码
# fh = logging.FileHandler('tmp.log',encoding='utf-8')
# # fh2 = logging.FileHandler('tmp2.log',encoding='utf-8')
# sh = logging.StreamHandler()
# logging.basicConfig(
# format='%(asctime)s - %(name)s - %(levelname)s[line :%(lineno)d]-%(module)s: %(message)s',
# datefmt='%Y-%m-%d %H:%M:%S %p',
# level= logging.DEBUG,
# # handlers=[fh,sh,fh2]
# handlers=[fh,sh]
# )
# logging.debug('debug 信息错误 test2')
# logging.info('warning 信息错误 test2')
# logging.warning('warning message test2')
# logging.error('error message test2')
# logging.critical('critical message test2')
# 做日志的切分
# import time
# from logging import handlers
# sh = logging.StreamHandler()
# rh = handlers.RotatingFileHandler('myapp.log', maxBytes=1024,backupCount=5) # 按照大小做切割
# fh = handlers.TimedRotatingFileHandler(filename='x2.log', when='s', interval=5, encoding='utf-8')
# logging.basicConfig(
# format='%(asctime)s - %(name)s - %(levelname)s[line :%(lineno)d]-%(module)s: %(message)s',
# datefmt='%Y-%m-%d %H:%M:%S %p',
# level= logging.DEBUG,
# # handlers=[fh,sh,fh2]
# handlers=[fh,rh,sh]
# )
# for i in range(1,100000):
# time.sleep(1)
# logging.error('KeyboardInterrupt error %s'%str(i))