ini配置文件读取-python

ini配置文件,是由多个section构成,每个section名用[]包含,每个section下面配置项类似key-value的形式,如
[appium] platformname = Android platformversion = 4.4.2 apppackage = com— appactivity = com— deviceName = D8YDU16325002121 port = 4723 timeout = 60 host = 127.0.0.1 [report] ReportFormal=

confighelper.py 读取的时候,调用使用ConfigParser的SafeConfigParser方法,获取指定section的配置信息

def getConfig(self,section): try: myconfig=self.conf.items(section) except: myconfig=None return myconfig

定义全局常量文件constant.py

run_path = os.getcwd() global cfg_path,log_path,report_path log_path = os.sep.join([util1.getrootpath(),'logs']) cfg_path=os.sep.join([util1.getrootpath(),'cfg','cfg.ini']) report_path=os.sep.join([util1.getrootpath(),'report']) user_cfg = os.sep.join([util1.getrootpath(),'cfg','user_info.json'])

读取配置文件方法

config=ConfigHelper(constant.cfg_path) self.capabilities['platformName']=config.getValue('appium', 'platformName')

posted on 2017-08-01 17:58  yanzilove  阅读(89)  评论(0)    收藏  举报