(转)Python中的ConfigParser模块使用详解
来源:互联网 发布:什么是数据挖掘技术 编辑:程序博客网 时间:2024/05/16 07:33
最近在学习ConfigParser模块读取配置文件 ,从网上搜来的东西,记录一下。:
1.基本的读取配置文件
-read(filename) 直接读取ini文件内容
-sections() 得到所有的section,并以列表的形式返回
-options(section) 得到该section的所有option
-items(section) 得到该section的所有键值对
-get(section,option) 得到section中option的值,返回为string类型
-getint(section,option) 得到section中option的值,返回为int类型,还有相应的getboolean()和getfloat() 函数。
2.基本的写入配置文件
-add_section(section) 添加一个新的section
-set( section, option, value) 对section中的option进行设置,需要调用write将内容写入配置文件。
3.基本例子
得到终端输出:
更新后的test.conf
4.Python的ConfigParser Module中定义了3个类对INI文件进行操作。分别是RawConfigParser、ConfigParser、SafeConfigParser。RawCnfigParser是最基础的INI文件读取类,ConfigParser、SafeConfigParser支持对%(value)s变量的解析。
设定配置文件test2.conf
使用RawConfigParser:
得到终端输出:
改用ConfigParser:
得到终端输出:
改用SafeConfigParser:
得到终端输出(效果同ConfigParser):
- (转)Python中的ConfigParser模块使用详解
- python ConfigParser模块详解
- python configParser模块详解(转载)
- python中ConfigParser模块使用
- Python 标准模块 ConfigParser(转)
- Python ConfigParser模块(转载)
- Python 解析配置模块之ConfigParser详解
- Python 解析配置模块之ConfigParser详解
- Python 解析配置模块之ConfigParser详解
- Python 解析配置模块之ConfigParser详解
- Python 解析配置模块之ConfigParser详解
- Python 解析配置模块之ConfigParser详解
- Python中ConfigParser模块的使用
- 【Python】配置文件解析模块ConfigParser使用实例
- Python 解析配置文件 (ConfigParser)模块
- PYTHON 配置文件模块 ConfigParser
- Python模块之: ConfigParser
- python 之ConfigParser模块
- Spring MVC 学习总结(九)——Spring MVC实现RESTful与JSON(Spring MVC为前端提供服务)
- 防sql注入
- tcpdump常用参数说明
- Sublime Text3 tab快捷键失效解决办法
- [torch] some bugs
- (转)Python中的ConfigParser模块使用详解
- Mysql实现企业级数据库主从复制架构实战
- R语言生存分析数据分析可视化案例
- Android DiskLruCache缓存工具封装
- python pandas 数据框 条件选取行列数据
- 数据结构与算法--Boyer-Moore和Rabin-Karp子字符串查找
- centos6.8下mosquitto分布式集群
- Shell编程基础篇-下
- Pycharm激活码