获取文件目录
2020-05-13 本文已影响0人
Leoguo小哥
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)
![](https://img.haomeiwen.com/i18762944/80a0192590aa7d73.png)