美文网首页
python入门 第十四天 更多模块

python入门 第十四天 更多模块

作者: xinmin | 来源:发表于2018-09-18 21:33 被阅读0次
  • 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")
    

相关文章

网友评论

      本文标题:python入门 第十四天 更多模块

      本文链接:https://www.haomeiwen.com/subject/dmyagftx.html