python读取ini配置文件,,python读取配置
python读取ini配置文件,,python读取配置
python读取配置文件的方法:
1. 引入库
python2.x
import ConfigParser
python3.x
import configparser
区别:python2.x每个单词开头都是大写,python3.x都是小写
2. 打开文件
python2.x
cf = ConfigParser.ConfigParser()cf.read(‘./config.ini‘, encoding=‘gbk‘)
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变量的实质,,python变量的实
- Python week1-复习,,编译器是把源程序的每
- python-----opencv显示指定大小并按键实现暂停、播放,,按
- Python对象继承set类型,,Python对象继承
- 小甲鱼Python第八讲课后习题,,0. 下面的循环会打
- python判断变量类型是否为List列表,,li =["hell
- Python--函数return多个值,,# 函数如果有多个r
- Python如何让读取文件内容为字符串 ?案例详解,,方法
- python Class:面向对象高级编程 Enum(枚举)、@unique,,注:
- 调用百度ocr的API,python简易版本,,调用百度ocr的AP
评论关闭