基础读取配置文件

  • -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的更多相关文章

  1. Python配置文件实现

    实现目标: 支持配置文件继承 支持本地配置文件 支持配置文件别名 简单的配置文件操作 最新的代码可以参考 https://github.com/blackmatrix7/matrix-toolkit/ ...

  2. python配置文件的加载

    背景: 微信机器人项目用到了mysql数据库配置,阿里云OSS上传文件配置:现在需要将这些配置参数统一写到一个配置文件中统一管理,而不是分散的写在代码中 1. 使用.ini文件作为配置文件 例如: s ...

  3. python配置文件转dict

    配置文件有很多种,如JSON,properties,conf,xml等. 除非需要跟别的语言进行交互,python本身是完全可以取代所有配置文件的.使用python进行配置可以使用非常灵活地执行一些逻 ...

  4. python配置文件读取

    在代码实现的过程中,我们经常选择将一些固定的参数值写入到一个单独的配置文件中.在python中读取配置文件官方提供了configParser方法. 主要有如下方法(找官文):   (这家伙很懒,直接复 ...

  5. python 配置文件 ConfigParser模块

    ConfigParser模块 用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser. 来看一个好多软件的常见文档格式如下 [DEFAULT] Se ...

  6. python配置文件

    python有两种配置文件,file.ini和file.json 一.ini文件如下: db_config.ini [baseconf] host=127.0.0.1 port=3306 user=r ...

  7. python配置文件configparser详解

    Python中一般需要配置文件,配置文件一般以.cfg, .conf, .ini结尾.配置文件可以将数据库抽离到以 .ini(Windows)结尾的文件中,这样做的优点在于可在配置文件中添加多个数据库 ...

  8. python:配置文件configparser

    #-*- coding:utf8 -*- # Auth:fulimei import configparser #第一个标签 conf=configparser.ConfigParser() conf ...

  9. python 配置文件返回的两种方式,写法不一样而已

    配置文件如下: [MODE]mode:{ "register":"all"} 或者 mode = {"register":"all ...

随机推荐

  1. (模拟) codeVs1083 && 洛谷P1014 Cantor表

    题目描述 Description 现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的.他是用下面这一张表来证明这一命题的: 1/1 1/2 1/3 1/4 1/5 … 2/1 2/ ...

  2. (二叉树 递归) leetcode 145. Binary Tree Postorder Traversal

    Given a binary tree, return the postorder traversal of its nodes' values. Example: Input: [1,null,2, ...

  3. Python菜鸟快乐游戏编程_pygame(4)

    Python菜鸟快乐游戏编程_pygame(博主录制,2K分辨率,超高清) https://study.163.com/course/courseMain.htm?courseId=100618802 ...

  4. jquery script两个属性

    今天使用jquery cdn时发现多了两个属性. <script   src="http://code.jquery.com/jquery-2.2.4.min.js"   i ...

  5. Thunk

    Thunk https://en.wikipedia.org/wiki/Thunk In computer programming, a thunk is a subroutine used to i ...

  6. Python-Struct

    从一个例子开始: >>> from struct import * >>> pack('hhl',1655, 255, 370) b'w\x06\xff\x00r\ ...

  7. GitHub:本地项目上传与团队协作

    第一部分:我的本次作业成果 我自己个人的github地址是:colintz的个人仓库 我们开发团队小组的github地址是:小组3集中营 第二部分:强烈推荐的github资源 对于和我一样,初次接触g ...

  8. Element-UI标签页el-tabs组件的拖动排序实现

    ElementUI的标签页组件支持动态添加删除,如下图: 但是这个组件不支持标签之间的拖动排序.那么我们自己怎样实现这个功能呢? 有一个叫vuedraggable的组件(https://github. ...

  9. L1-Day13

    1.Being late is an unforgivable sin here.[我的翻译]在北京,迟到是不可饶恕的罪名.[标准答案]在这里迟到是不可原谅的.[对比分析]对自己的也是醉醉的了,Bei ...

  10. Corn Fields POJ - 3254 (状压dp)

    题目链接: Corn Fields  POJ - 3254 题目大意:给你一个n*m的矩阵,矩阵的元素只包括0和1,0代表当前的位置不能放置人,1代表当前的位置可以放人,当你决定放人的时候,这个人的四 ...