Python解析配置文件模块:ConfigPhaser
2018-07-20 22:22
399 查看
import configparser as pa # [SectionA] # a = aa # b = bb # c = cc # [SectionB] # optionint = 1 # optionfloat = 1.1 # optionstring = string #https://www.cnblogs.com/anpengapple/p/5095133.html with open(r"E://test.ini", 'r') as fr: cfg=pa.ConfigParser() cfg.read_file(fr) secs = cfg.sections() print(secs) #['SectionA', 'SectionB'] ops0 = cfg.options(secs[0]) #['a', 'b', 'c'] ops1 = cfg.items(secs[1]) print (ops0) #['a', 'b', 'c'] print (ops1) #[('optionint', '1'), ('optionfloat', '1.1'), ('optionstring', 'string')] print( cfg.getint(secs[1], 'optionint') ) print(cfg.get(secs[1],'optionstring'))
输出结果:
['SectionA', 'SectionB'] ['a', 'b', 'c'] [('optionint', '1'), ('optionfloat', '1.1'), ('optionstring', 'string')] 1 string
方法解释说明
相关文章推荐
- [zz]python模块之ConfigParser: 用python解析配置文件
- Python解析配置文件模块:ConfigPhaser
- python模块之ConfigParser: 用python解析配置文件
- python模块之ConfigParser: 用python解析配置文件
- python ConfigParser模块 配置文件解析
- 【Python】配置文件解析模块ConfigParser使用实例
- Python配置文件解析模块ConfigParser使用实例
- python中用Configparser模块解析配置文件
- python模块之ConfigParser: 用python解析配置文件[zt]
- python模块之ConfigParser:解析配置文件模块
- python-配置解析模块configparser-读取配置文件-遍历配置文件
- ConfigParser模块学习: 用python解析配置文件
- Python之配置文件解析模块ConfigParser简介
- Python 解析配置文件 (ConfigParser)模块
- Python 模块之 ConfigParser: 用 Python 解析配置文件
- Nginx http_core模块 配置文件解析
- Python用ConfigParser解析INI配置文件
- 使用python的ConfigParser模块方便的读取配置文件
- 在python中实现自定义配置文件解析及应用技巧[yaml and ConfigParser] 推荐
- Python自动化测试 -ConfigParser模块读写配置文件