首页 > 编程语言 > 详细

PYTHON中读取文件配置

时间:2019-12-28 18:51:53      阅读:66      评论:0      收藏:0      [点我收藏+]

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

技术分享图片

PYTHON中读取文件配置

原文:https://www.cnblogs.com/East-fence/p/12112382.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!