获取配置文件信息——configparser

配置文件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

猜你喜欢

转载自www.cnblogs.com/langhuagungun/p/9028552.html