python 配置文件__ConfigParser
基础读取配置文件
- -read(filename) 直接读取文件内容
- -sections() 得到所有的section,并以列表的形式返回
- -options(section) 得到该section的所有option
- -items(section) 得到该section的所有键值对
- -get(section,option) 得到section中option的值,返回为string类型
- -getint(section,option) 得到section中option的值,返回为int类型,还有相应的getboolean()和getfloat() 函数。
具体详见文章:https://www.cnblogs.com/feeland/p/4514771.html
do_config.py
# -*- conding:utr- -*-
#@Time :// :
#@Author:GYP测试
#@File :do_config.py import configparser
class ReadConfig:
def read_config(self,file_name,section,option):
cf=configparser.ConfigParser()
cf.read('case.config',encoding='utf-8')#打开文件
return cf.get(section,option)
if __name__ == '__main__':
res=ReadConfig().read_config('case.config','MODE','mode')
print(res) # #读取配置文件的数据
#
# print(cf.sections())
# print(cf.items('PYTHON'))
#
#
# res_1=cf.get('MODE','mode')
# print(res_1)
# res_2=cf['LEMON']['boss']
# print(res_2)
#
# #数据类型讨论的问题
# #--------都是字符串--------数据类型转换 eval()
# print(type(cf.get('PYTHON','num')))
case.config
---------------------------------------------------------------------------------------------------------------------
[MODE] mode=[1,3] [PYTHON] num=89
name=小郭 [LEMON] num=33
age=18
boss=华华
--------------------------------------------------------------------
gyp1101.py
# -*- conding:utr-8 -*-
#@Time :2018/11/2 15:25
#@Author:GYP测试
#@File :gyp1101.py
from openpyxl import load_workbook
from class_1103.do_config import ReadConfig
class datedd:
def __init__(self,file_name,sheet_name):
self.file_name=file_name
self.sheet_name=sheet_name
def get_header(self):
wb = load_workbook(self.file_name)
sheet = wb[self.sheet_name]
header=[]
for i in range(1,sheet.max_column+1):
header.append(sheet.cell(1,i).value)
# print(header)
return header def get_data(self):
'''mode:控制是否执行所有的用例 默认值为all 为all就执行的用例
如果不等于all的话 就进入分值 判断
mode的值 只能输入 all 列表 这两种类型的参数'''
mode=ReadConfig().read_config('case.config','MODE','mode') wb=load_workbook(self.file_name)
sheet=wb[self.sheet_name]
header=self.get_header()
test_data=[]
for i in range(2,sheet.max_row+1):
sub_data={}
for j in range(1,sheet.max_column+1):
sub_data[header[j-1]]=sheet.cell(i,j).value
test_data.append(sub_data)
#根据mode值去进行判断
if mode=='all':#执行所有用例
final_data=test_data
else:
final_data=[]
for item in test_data:
if item['case_id'] in eval(mode):
final_data.append(item)
print(final_data)
return final_data
if __name__ == '__main__':
datedd('xg.xlsx','python1').get_data()
# datedd('xg.xlsx','python1').get_header()
通过配置文件可以修改具体 执行那些用例
python 配置文件__ConfigParser的更多相关文章
- Python配置文件实现
实现目标: 支持配置文件继承 支持本地配置文件 支持配置文件别名 简单的配置文件操作 最新的代码可以参考 https://github.com/blackmatrix7/matrix-toolkit/ ...
- python配置文件的加载
背景: 微信机器人项目用到了mysql数据库配置,阿里云OSS上传文件配置:现在需要将这些配置参数统一写到一个配置文件中统一管理,而不是分散的写在代码中 1. 使用.ini文件作为配置文件 例如: s ...
- python配置文件转dict
配置文件有很多种,如JSON,properties,conf,xml等. 除非需要跟别的语言进行交互,python本身是完全可以取代所有配置文件的.使用python进行配置可以使用非常灵活地执行一些逻 ...
- python配置文件读取
在代码实现的过程中,我们经常选择将一些固定的参数值写入到一个单独的配置文件中.在python中读取配置文件官方提供了configParser方法. 主要有如下方法(找官文): (这家伙很懒,直接复 ...
- python 配置文件 ConfigParser模块
ConfigParser模块 用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser. 来看一个好多软件的常见文档格式如下 [DEFAULT] Se ...
- python配置文件
python有两种配置文件,file.ini和file.json 一.ini文件如下: db_config.ini [baseconf] host=127.0.0.1 port=3306 user=r ...
- python配置文件configparser详解
Python中一般需要配置文件,配置文件一般以.cfg, .conf, .ini结尾.配置文件可以将数据库抽离到以 .ini(Windows)结尾的文件中,这样做的优点在于可在配置文件中添加多个数据库 ...
- python:配置文件configparser
#-*- coding:utf8 -*- # Auth:fulimei import configparser #第一个标签 conf=configparser.ConfigParser() conf ...
- python 配置文件返回的两种方式,写法不一样而已
配置文件如下: [MODE]mode:{ "register":"all"} 或者 mode = {"register":"all ...
随机推荐
- npm_config_
npm script时会带一些参数变量,例如: "test": "node scripts/tools/test.js --name=test111" 平常我们 ...
- python 之金玉良言 或许是最后一次给自己系统总结--已结
jar tvf xxx.jar vim xxx.jar 配置一下 notepad++ F5 cmd /k D:"Program Files (x86)"\python\python ...
- OCC上下文设置显示模式
#include <AIS_InteractiveContext.hxx> 通过AIS_InteractiveContext::SetDisplayMode()函数来设置 void Se ...
- python3 练手实例1 计算三角形周长和面积
def j(): a,b,c=map(float,input('请输入三角形三条边的长度,用空格隔开:').split()) if a>0 and b>0 and c>0 and a ...
- springMVC中数据流解析与装载
最近在看springmvc原理时,看到一篇比较赞的博文,留存学习,如果侵权,请告知,立删. 地址: https://my.oschina.net/lichhao/blog/172562
- vue.js学习系列-第一篇(代码)
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"> ...
- 手把手使用Git?
下载和安装:Git下载和安装教程 学习使用Git:学习Git 安装TortoiseGit:教程 TortoiseGit与Git生成SSH密钥添加到GitHub账号的简单方法:解决方法
- 使用git把本地目录传到远程仓库
需求: 要把本地不为空的一个目录和远程现有的一个仓库关联 步骤如下: git init //生成.git目录 git add . //把当前目录里的文件加入到暂存区 git commit -m '上传 ...
- SpringSecurity在Springboot下使用的初步体验
SpringSecurity曾经在十年前非常火热,只要是做权限系统,当时几乎非用它不可,记得是在XML文件里一堆的配置.曾几何时,Shiro冒了出来,以其简洁和轻量的风格慢慢地捕获了众多码农的心,从此 ...
- MySQL对以特定名字开头的数据库进行授权
对以"db_1"开头的数据库进行授权 grant all privileges on `db_1%`.* to dp_admin identified by 'password'; ...