- configparser模块:处理配置文件的
""" ini文件 [name] age = 19 gender = 0 xxx = aaa [zhangsan] age = 21 gender = man """ import configparser con = configparser.ConfigParser() con.read("ini", encoding='utf-8') res = con.sections() print(res) ret = con.option("name") print(ret)
- shutil模块:高级的文件、文件夹、压缩包处理模块
import shutil # 读文件写到新文件中 shutil.copyfileobj(open("old.xml", 'r'), open("new.xml", 'w')) # 拷贝文件夹 shutil.copytree('folder1', 'folder2', ignore=shutil.ignore_patterns('*.pyc', 'tmp'))
- logging模块:方便写日志
import logging logging.basicConfig(filefilename='log.log', format='%(asctime)s - %(name)s - %(levelname)s - %(module)s: %(message)s', datefmt = '%Y-%m-%d %H:%M:%S %p', level = 10,) logging.error("ssss")
网友评论