首页 > 其他 > 详细

获取配置文件信息——configparser

时间:2018-05-12 14:45:57      阅读:197      评论:0      收藏:0      [点我收藏+]
配置文件host.int格式如下:
[host]
product=xxxxxxxxxx
test=xxxxxxxxxx





python 3.x代码如下:
import os,configparser
def filePath(path):
return os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))),path)
def getHostData():
#获取配置文件host信息
cf=configparser.ConfigParser()
cf.read(filePath(‘config\\host.ini‘))
product=cf.get(‘host‘,‘product‘)
test=cf.get(‘host‘,‘test‘)
return product,test

获取配置文件信息——configparser

原文:https://www.cnblogs.com/langhuagungun/p/9028552.html

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