首页 > 其他 > 详细

读取excel,将读取到的数据存储到列表和对象中(2)

时间:2020-07-07 18:29:08      阅读:75      评论:0      收藏:0      [点我收藏+]
#基础用例数据类
class CaseInfo:
def __init__(self,case_id,case_name,case_module,case_pri,case_step,case_result):
self.case_id=case_id
self.case_name=case_name
self.case_module=case_module
self.case_pri=case_pri
self.case_step=case_step
self.case_result=case_result



#读取excel为各种类型:列表,类
import os
import xlrd
from pritices_daily import case_infos
#1,读取数据存到列表中:[[用例编号,用例名称,所在模块...],[....],[......]]
current_path = os.path.dirname(__file__)
excel_path = os.path.join(current_path, ‘../data/testcases.xlsx‘)
workbook = xlrd.open_workbook(excel_path) # 打开工作簿
sheet = workbook.sheet_by_index(0) # 打开第一个表
all_case_info1=[]
for i in range(1,sheet.nrows):
case_info = []
for j in range(0,sheet.ncols):
case_info.append(sheet.cell_value(i,j))
all_case_info1.append(case_info)

print(all_case_info1)

#2,做成类形成
all_case_info2=[]
for i in range(1,sheet.nrows):
case_id = sheet.cell_value(i,0)
case_name = sheet.cell_value(i,1)
case_module = sheet.cell_value(i,2)
case_pri = sheet.cell_value(i,3)
case_step = sheet.cell_value(i,4)
case_result = sheet.cell_value(i,5)
CaseInfo=case_infos.CaseInfo(case_id, case_name, case_module, case_pri, case_step, case_result)
all_case_info2.append(CaseInfo)

print(all_case_info2[0].case_id)



读取excel,将读取到的数据存储到列表和对象中(2)

原文:https://www.cnblogs.com/tingting-yang/p/13261896.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!