import configparser
import os, sys
parent_dir = os.path.dirname(os.path.abspath(__file__))
# 实例化configParser对象
config = configparser.ConfigParser()
config.read(parent_dir + "/config.init",encoding='utf-8') # 读取配置文件采用绝对路径
(config.get('environment', 'filename')
[environment]
filename=order_20161101_w.csv
outfilename=test写入ODconfig测试.csv
-read(filename)
直接读取文件内容
-sections()
得到所有的section,并以列表的形式返回
-options(section)
得到该section的所有option
-items(section)
得到该section的所有键值对
-get(section, option)
得到section中option的值,返回为string类型
-getint(section, option)
得到section中option的值,返回为int类型,还有相应的getboolean()
和getfloat()
函数。