在很多场景中,我们都需要用到configparser模块,用来记录配置文件,所以就做下记录。
import os
import configparser
path = os.getcwd()#获取相对路径,D:\untitled\fuxi\fuxi1
config = configparser.ConfigParser()
path1 = path + r'\1\1.ini'
#config.read(self, filenames, encoding=None)
b = config.read(path1,encoding='utf-8')
#['1.ini']读取文件,1.ini的路径要写全
#a = config.sections()
#['browserType', 'testServer', 'browserPath', 'excelPath', 'scrPath']
# 读取selction的名字以列表形式展示
c = config['browserType']['browserName']
#Chrome,读取browserType下的browserName的值
d = config.get('browserType','browserName')
#Chrome,读取browserType下的browserName的值