#!/usr/bin/python # -*- coding: GBK -*- # ##@package # # @todo: # # @author: Alee # @date 2018-6-5 ÏÂÎç08:20:53 # @version 1.0 # # @note: # #--------------------------------------------------------------------- import ConfigParser class ReadConfig(): def __init__(self, filePath): self.__config = ConfigParser.ConfigParser() self.__config.read(filePath) def GetValue(self, section, option, default=None, isThrowException=False): try: return self.__config.get(section, option); except Exception, err: if not isThrowException: return default; raise Exception, "Error:ÅäÖÃÎÊÌâ,%s"%err; get = GetValue; def GetInt(self, section, option, default = 0, isThrowException=False): try: return self.__config.getint(section, option); except Exception, err: if not isThrowException: return default; raise Exception, "Error:ÅäÖÃÎÊÌâ,%s"%err; getint = GetInt; def GetBoolean(self, section, option, default = False): try: return self.__config.getboolean(section, option); except ValueError: default = str(default).lower(); if default not in self.__config._boolean_states: return False; else: return self.__config._boolean_states[default]; getboolean = GetBoolean; def HasSection(self, section): return self.__config.has_section(section) def HasOption(self, section, option): return self.__config.has_option(section, option) #=============================================================================== # ## ¶ÁÈ¡EvalµÄÖµ # def GetEvalConfig(path): # with open(path, "r") as file: # content = file.read() # try: # value = eval(content) # except: # value = None # # return value #===============================================================================