【转】python -ConfigParser模块
转自:https://blog.csdn.net/zm2714/article/details/8002125#
configParser 模块用于操作配置文件 注:Parser汉译为“解析”之意。
配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键=值)。
配置文件的组成及命名:配置文件(INI文件)由节(section)、键、值组成。
ConfigParser方法
1、config=ConfigParser.ConfigParser()
创建ConfigParser实例
2、config.sections()
返回配置文件中节序列
3、config.options(section)
返回某个section节中的所有键的序列
4、config.get(section,option)
返回section节中,option键对应的值
5、config.add_section(str)
添加一个配置文件节点(str)
6、config.set(section,option,val)
设置section节点中,键名为option的值(val)
7、config.read(filename)
读取配置文件
8、config.write(obj_file)
写入配置文件
还没有评论,来说两句吧...