ConfigParser使用:1.获取所有section为list,2.指定section具体值,并转换为dict

# -*- coding: utf-8 -*-
import ConfigParser
import json


class PartConf():
def __init__(self,env):
if env != None:
self.env = env
self.Part_Conf_List = []
self.Part_Conf = {}
self.Part_conf = ConfigParser.ConfigParser()
self.Part_conf.read("./conf/Part_conf.properties")
else:
return Exception

  # 1.获取所有section为list

def Get_PartConf_List(self):
self.Part_Conf_List = self.Part_conf.options(self.env)
return self.Part_Conf_List

  # 2.指定section具体值,并转换为dict
    def Get_PartConf(self,Part_Name = None):
self.Part_Conf = json.loads(str(self.Part_conf.get(self.env,Part_Name)).strip())
return self.Part_Conf
posted @ 2017-09-21 15:24  一路漂泊  阅读(1461)  评论(0编辑  收藏  举报