read_ini.py
import configparser,os class ReadIni(): def __init__(self,node=None,file_name=None): if file_name == None: file_name = os.path.abspath('../')+"/config/ElementConfig.ini" else: file_name = os.path.abspath('../') + "/config/"+ file_name +".ini" if node == None: self.node = "CreateClueElement" else: self.node = node self.cf = self.load_ini(file_name) #加载文件 def load_ini(self,file_name): cf = configparser.ConfigParser() cf.read(file_name,encoding="utf-8") return cf #获取value的值 def get_value(self,key): data = self.cf.get(self.node, key) return data if __name__ == '__main__': read_init = ReadIni('ApiAddressConfig','publicParameters') print(read_init.get_value('rip_addr'))