东篱野鹤

导航

PYTHON中读取文件配置

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、执行结果

posted on 2019-12-28 17:14  东篱野鹤  阅读(253)  评论(0)    收藏  举报