博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python configParser 模块
阅读量:7094 次
发布时间:2019-06-28

本文共 839 字,大约阅读时间需要 2 分钟。

configParser 模块用于操作配置文件

配置文件(INI文件)由节(section)、键、值组成
1、config=ConfigParser.ConfigParser() 创建ConfigParser实例
2、config.sections() 返回配置文件中节序列
3、config.options(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) 写入配置文件
9、config.get() 返回文本 config.getint()返回整数
10、config.remove_option( section, option)
11、config.remove_section( section)
案例:
import ConfigParser
import os
class ReadWriteConfFile:
currentDir=os.path.dirname(file) @staticmethod
br/>filepath=currentDir+os.path.sep+"inetMsgConfigure.ini"
@staticmethod
def getConfigParser():
cf=ConfigParser.ConfigParser()
cf.read(ReadWriteConfFile.filepath)
return cf

转载于:https://blog.51cto.com/weadyweady/2133117

你可能感兴趣的文章
Oracle 物化视图
查看>>
Mybatis Mapper.xml 配置文件中 resultMap 节点的源码解析
查看>>
Hadoop
查看>>
【Unity】手游资源热更新策略探讨
查看>>
没有任何技术含量的一片日志
查看>>
我的友情链接
查看>>
android开发--RelativeLayout用到的一些重要的属性
查看>>
Oracle大表数据排序后分页查询效率很慢
查看>>
JFBlog 1.0 发布,基于 JFinal 的 Java 轻博客
查看>>
RHEL6配置Kdump
查看>>
nginx 跨域配置
查看>>
Redhat6.9更换yum源
查看>>
【转】为什么大型网站前端使用 PHP 后台逻辑用 Java?
查看>>
json_decode参数
查看>>
数据结构之图
查看>>
JSON 数组转化 OC的数组转化成OC格式的字符串
查看>>
spring retry重试机制原理解析(手写原理)
查看>>
编译安装web服务
查看>>
PHP: CodeIgniter3中函数名不能与控制器名相同的问题
查看>>
SSDCRM紧急发布一个安全漏洞补丁
查看>>