python——一些常用的方法类
2024-09-27 10:23:18
测试的时候经常需要使用一些方法都整理放在一起,方便调用
首先一些基本的配置引入
localReadConfig = readConfig.ReadConfig()
proDir = readConfig.proDir
log = Log.get_log() caseNo = 0
根据xls_name和sheet_name来读取数据
def get_xls(xls_name, sheet_name):
"""
get interface data from xls file
:param xls_name:
:param sheet_name:
:return:
"""
cls = []
# get xls file's path
xls_path = os.path.join(proDir, 'testFile', 'case', xls_name)
# open xls file
file = xlrd.open_workbook(xls_path)
# get sheet by name
sheet = file.sheet_by_name(sheet_name)
# get one sheet's rows
nrows = sheet.nrows
for i in range(nrows):
if sheet.row_values(i)[0] != u'case_name':
cls.append(sheet.row_values(i))
return cls
将结果写入到excel中
def write_result_into_xls(xls_path, sheet, wb, result, row, col):
sheet.write(row, col, result)
wb.save(xls_path)
def write_results_into_xls(xls_name, sheet_name, results, col):
xls_path = os.path.join(proDir, 'testFile', 'case', xls_name)
rb = xlrd.open_workbook(xls_path)
wb = copy.copy(rb)
sheet = wb.get_sheet(sheet_name)
for i in range(len(results)):
write_result_into_xls(xls_path, sheet, wb, results[i], i+1, col)
正则表达式匹配
用import.re导入正则表达式模块
用re.complie()函数创建一个Regex对象(记得使用原始字符串)
向Regex对象的search()方法传入想查找的字符串。它返回一个Match对象
调用Macth对象的group()方法,返回实际匹配文本的字符串
最新文章
- StartUML反向(逆向)Java工程通过代码生成类图
- 支持Java Spring MVC
- Redis总结(二)C#中如何使用redis
- OpenResty 安装及使用(第一篇安装)
- 【UR #4】元旦三侠的游戏(博弈论+记忆化)
- Java日志性能
- 函数malloc的实现源代码
- logstash+elasticsearch+kibana快速搭建日志平台
- socket编程部分API
- C# 微信开发-----微信会员卡(三)激活会员卡
- gulp + gulp-better-rollup + rollup 构建 ES6 开发环境
- POI 海量数据/大数据文件生成SXSSFWorkbook使用简介
- js----DOM对象(事件)
- nyoj-0469-擅长排列的小明 II(找规律)
- Windows下Python安装: requires numpy+mkl 和ImportError: cannot import name NUMPY_MKL
- C语言之选择结构
- Egret 菜鸟级使用手册--第二天
- Scrapy爬取美女图片第三集 代理ip(下)
- linux nginx 配置php
- C# 使用this的形参