python3读取conifg配置文件

config文件 config.ini

[browserType]
#browserName = Firefox
browserName = Chrome
#browserName = IE

[testServer]
URL = https://cn.bing.com/
#URL = www.google.com

import os
import configparser

class ReadIniFile:
    def get_value(self):
        root_dir = os.path.dirname(os.path.abspath("."))
        print (root_dir)

        config = configparser.ConfigParser()
        file_path = root_dir + "/config/config.ini"
        print(file_path)
        config.read(file_path)

        browser = config.get("browserType","browserName")
        url = config.get("testServer","URL")

        return(browser,url)


if __name__ == '__main__':
    read_ini_file = ReadIniFile()
    print(read_ini_file.get_value())

 




上一篇:Win11 vagrant up报错解决方案


下一篇:第八天学习内容