configparser模块        # 该模块适用于配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键=值)。
import configparser
config = configparser.ConfigParser()
config['bitbucket.org'] = {'User':'hg'}
config['topsecret.server.com'] = {'Host Port':'','ForwardX11':'no'}
with open('example.ini', 'w') as configfile:config.write(configfile)
#---------------------------查找文件内容,基于字典的形式
config = configparser.ConfigParser()
config.read('example.ini')
print(config.sections())
print('bytebong.com' in config) # False
print(config['bitbucket.org']["user"]) # hg
for key in config['bitbucket.org']:print(key) # 注意,有default会默认default的键
print(config.options('bitbucket.org')) # 同for循环,找到'bitbucket.org'下所有键
print(config.items('bitbucket.org')) # 找到'bitbucket.org'下所有键值对
print(config.get('bitbucket.org','compression')) # yes get方法Section下的key对应的value
#---------------------------增删改
config = configparser.ConfigParser()
config.read('example.ini')
config.add_section('yuan') # 增加section
config.remove_section('bitbucket.org') # 删除一个section
config.remove_option('topsecret.server.com',"forwardx11") # 删除一个配置项
config.set('topsecret.server.com','k1','')
config.set('yuan','k2','')
config.write(open('new2.ini', "w")) import logging
# logging.basicConfig(level=logging.WARNING,
# format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
# datefmt='%a, %d %b %Y %H:%M:%S')
# logging.debug('debug message') # 低级别的 # 排错信息
# logging.info('info message') # 正常信息
# logging.warning('warning message') # 警告信息
# logging.error('error message') # 错误信息
# logging.critical('critical message') # 高级别的 # 严重错误信息
# # basicconfig 简单 能做的事情相对少 # 中文的乱码问题 # 不能同时往文件和屏幕上输出
#
# 配置log对象 稍微有点复杂 能做的事情相对多
import logging
logger = logging.getLogger()        #logger.setLevel(logging.DEBUG)
fh = logging.FileHandler('log.log',encoding='utf-8') # 创建一个文件控制对象
sh = logging.StreamHandler() # 创建一个屏幕控制对象
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
formatter2 = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s [line:%(lineno)d] : %(message)s')
# 文件操作符 和 格式关联
fh.setFormatter(formatter)
sh.setFormatter(formatter2)
# logger 对象 和 文件操作符 关联
logger.addHandler(fh)
logger.addHandler(sh)
logging.debug('debug message') # 低级别的 # 排错信息
logging.info('info message') # 正常信息
logging.warning('警告错误') # 警告信息
logging.error('error message') # 错误信息
logging.critical('critical message') # 高级别的 # 严重错误信息

configparser logging的更多相关文章

  1. 常用模块(hashlib,configparser,logging)

    常用模块(hashlib,configparser,logging) hashlib hashlib 摘要算法的模块md5 sha1 sha256 sha512摘要的过程 不可逆能做的事:文件的一致性 ...

  2. hashlib,configparser,logging模块

    一.常用模块二 hashlib模块 hashlib提供了常见的摘要算法,如md5和sha1等等. 那么什么是摘要算法呢?摘要算法又称为哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度 ...

  3. hashlib,configparser,logging,模块

    一,hashlib模块 算法介绍 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢?摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一 ...

  4. python 全栈开发,Day26(hashlib文件一致性,configparser,logging,collections模块,deque,OrderedDict)

    一.hashlib文件一致性校验 为何要进行文件一致性校验? 为了确保你得到的文件是正确的版本,而没有被注入病毒和木马程序.例如我们经常在网上下载软件,而这些软件已经被注入了一些广告和病毒等,如果不进 ...

  5. 常用模块(subprocess/hashlib/configparser/logging/re)

    一.subprocess(用来执行系统命令) import os cmd = r'dir D:xxx | findstr "py"' # res = subprocess.Pope ...

  6. 内置函数 hashlib configparser logging 模块 C/S B/S架构

    1.内置函数 # 内置的方法有很多 # 不一定全都在object中 # class Classes: # def __init__(self,name): # self.name = name # s ...

  7. 序列化 ,hashlib ,configparser ,logging ,collections模块

    # 实例化 归一化 初始化 序列化 # 列表 元组 字符串# 字符串# .......得到一个字符串的结果 过程就叫序列化# 字典 / 列表 / 数字 /对象 -序列化->字符串# 为什么要序列 ...

  8. 铁乐学python26_hashlib+configparser+logging模块

    大部份内容摘自博客http://www.cnblogs.com/Eva-J/ hashlib模块算法介绍 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢? ...

  9. configparser logging collections 模块

    configparser 模块: 这是一个写入的模块就是把你的信息给写入的模块 #这是一个把信息写入example文件内import configparserconfig = configparser ...

  10. python常用模块补充hashlib configparser logging,subprocess模块

    一.hashlib模板 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢?摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定 ...

随机推荐

  1. ______________从时间超限到800ms 到200ms——————2098

    分拆素数和 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted S ...

  2. div 弹出 居中

    function show_tc_conv(){var x=jq13(window).width()/2;var y=jq13(window).height()/2; var div_w=jq13(& ...

  3. SpringBoot之旅第七篇-Docker

    一.引言 记得上大三时,要给微机房电脑安装系统,除了原生的操作系统外,还要另外安装一些必要的开发软件,如果每台电脑都重新去安装的话工作量就很大了,这个时候就使用了windows镜像系统,我们将要安装的 ...

  4. 安装JPype时出现的 Unable to find vcvarsall.bat

    解决方案,在网上找到的,mark一下,亲测有效 C:/Python31/Lib/distutils目录下的msvc9compiler.py中 修改MSVCCompiler函数:vc_env = que ...

  5. javascript实现弹层效果

    首先,需要有一个按钮来模拟登录: <button id="btnLogin"class="login-btn">登录</button> ...

  6. idea 调试工具的使用

    原文:https://blog.csdn.net/hao_hl1314/article/details/53120918 Intellij IDEA Debug调试区工具的使用方法 快捷键F9     ...

  7. php5.6.30开启redis扩展

    注:5.6版本的php一定要下载phpredis3.0以上的版本,之前自己下载用的2.2.4的redis,安装配置完成后,PHP死活不支持redis的扩展,通过phpinfo打印也压根看不到,重复服务 ...

  8. .net 操作xml --移除注释节点

    /// <summary> /// xml字符串转xml文档 忽略注释信息 /// </summary> /// <param name="sXml" ...

  9. Farseer.net轻量级ORM开源框架 V1.x 入门篇:表实体类映射

    导航 目   录:Farseer.net轻量级ORM开源框架 目录 上一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:数据库上下文 下一篇:Farseer.net轻量级ORM开源框 ...

  10. SCCM大致安装过程,参考前辈教程完成部署

    本安装sccm主站点服务器准备 参考:http://stephen1991.blog.51cto.com/8959108/1529864 1.  准备三台服务器 ,注:所有服务器需要安装 .net3. ...