#ini文件

[web_config]
#前台ldap登陆:
login_name=ut251
login_pwd=wanghu123

读取ini文件内容

def read_config(section, key):
    try:
        config = configparser.ConfigParser()  # 类实例化
        # ini文件路径
        config_path = os.path.join(product_path, "config.ini")
        config.read(config_path)
        vilue = config.get(section, key)
        return vilue
    except Exception as e:
        return ('config文件获取失败:%s' % e)
if __name__ == '__main__':
    a = read_config("web_config", "login_name")
    print(a)

 

posted on 2024-04-24 14:37  会锻炼的猪  阅读(59)  评论(0编辑  收藏  举报