python读取ini配置文件
2018-10-05 20:22
609 查看
python读取配置文件的方法:
1. 引入库
python2.x
import ConfigParser
python3.x
import configparser
区别:python2.x每个单词开头都是大写,python3.x都是小写
2. 打开文件
python2.x
cf = ConfigParser.ConfigParser() cf.read('./config.ini')
python3.x
cf = configparser.ConfigParser() cf.read('./config.ini', encoding='gbk')
3. 读取信息
input_path = cf.get('input', 'path') trade_type = cf.getint('trade', 'trade_type')
读取信息通过get系列函数:
参数1是节(section);
参数2是键;
返回的是值。
相关文章推荐
- Python中INI配置文件的读取
- 通过python读取ini配置文件
- python读取配置文件ini
- python环境下django增加读取ini配置文件功能
- Python读取修改ini配置文件[ConfigParser]
- Python recipe(11):读取ini配置文件
- Python读取INI配置文件
- 如何使用Python3读取配置文件(ini)
- 通过python读取ini配置文件
- python读取/写入配置文件ini方法
- 通过python读取ini配置文件
- Python读取ini配置文件
- Python读取ini配置文件
- python3配置文件ini读取方法
- python 读取ini配置文件模块 configobj 介绍
- Python读取ini配置文件
- Python读取ini配置文件
- Python + Selenium自动化测试 -- 读取ini配置文件
- Python读取修改ini配置文件[ConfigParser]
- 批处理读取ini配置文件