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())