1, 配置文件. INI
- # 配置测试资源
- [BrowerType]
- brawerName = Chome
- [testSever]
- BaseUrl = http://www.baidu.com
2, 读取配置文件信息
- import configparser
- def read_configFile():# 读取配置文件
- config = configparser.ConfigParser()
- file_path = path+"\config\config.ini"# 配置文件路径
- # print(file_path)
- config.read(file_path,encoding="utf-8")#encoding="utf-8", 读取文件时汇报编码错误
- brower = config.get("BrowerType","brawerName")
- baseUrl = config.get("testSever","BaseUrl")
- return brower,baseUrl
- if __name__ == '__main__':
- conf = read_configFile()
- print(conf)
3, 执行结果
来源: http://www.bubuko.com/infodetail-3354527.html