1、配置文件.ini
1 #配置测试资源 2 [BrowerType] 3 brawerName = Chome 4 [testSever] 5 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、执行结果
原文:https://www.cnblogs.com/East-fence/p/12112382.html