码迷,mamicode.com
首页 > 编程语言 > 详细

python读取ini配置文件

时间:2018-10-05 21:02:53      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:3.x   parser   div   trade   section   配置文件   入库   参数   pre   

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配置文件

标签:3.x   parser   div   trade   section   配置文件   入库   参数   pre   

原文地址:https://www.cnblogs.com/zhugaopeng/p/9745746.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!