class ReadConfig:
"""定义一个读取配置文件的类"""
def __init__(self, filepath=None):
if filepath:
configpath = filepath
else:
root_path = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
configpath = root_path +"\env.ini"
print(configpath)
self.cf = configparser.ConfigParser()
self.cf.read(configpath)
print(self.cf.options("trunk"))
def get_config(self, confname, param):
value =self.cf.get(confname, param)
return value
if __name__ =='__main__':
test = ReadConfig()
name = test.get_config("trunk", "host")
print(name)
网友评论