configparser----配置文件模块

配置文件配置方法:

[ElementProfile]
landing=id:btn_account
error_message=xpath://div[@class='pop_head']/div/span
username_error=xpath://div[@class='username_msg msg']/span
username=id:username
error_content=xpath://div[@class='protocol']/a[@ href="//about.58.com/home2/home_pc/syxyjgg/771.html"]

configparser模块

1、第三方模块安装:pip install configparser

2、导入模块:import configparser

3、模块的使用:

 1 import configparser
 2 
 3 class ReaDconfigurationFile(object):
 4     def __init__(self,file_name=None , node=None):
 5         if file_name == None:
 6             file_name = r'F:项目京东登陆TestcfgConfiguration_file.ini'
 7         if node == None:
 8             self.node = 'ElementProfile'
 9         self.file = self.read_file(file_name)
10 
11     #加载配置文件
12     def read_file(self,file_name):
13         file = configparser.ConfigParser()
14         file.read(file_name)
15         return file
16 
17     #读取配置文件的value值
18     def obtain_ini_value(self,key):
19         file_value=self.file.get(self.node,key)
20         return file_value
原文地址:https://www.cnblogs.com/zihkj/p/12163762.html