標籤:lis gdi __name__ 從表 turn 表頭 work ber 介面
import xlrd
#將excel中資料轉換為列表
def excel_to_list(file,tag):
data_list=[]
#解析檔案
book=xlrd.open_workbook(file)
# print(type(book))
#擷取到自己想要的標籤頁
tag=book.sheet_by_name(tag)
#擷取tag頁行數
row_num=tag.nrows
#擷取tag頁列數
# cols_num=tag.ncols
# print(row_num,cols_num)
#擷取表頭,及第一行行資料
header=tag.row_values(0)
#print(header)
#從表頭下一行開始讀
for i in range(1,row_num):
#讀書沒一行資料
row_data=tag.row_values(i)
#等長兩列錶轉為字典,zip函數等長處理, 表頭為key,用例中資料為value。
d=dict(zip(header,row_data))
# print(d)
data_list.append(d)
return data_list
#在資料列表中根據測試案例名稱擷取對應的用例字典
def get_test_data(test_name,test_list):
for test_dic in test_list:
if test_name==test_dic["test_name"]:
return test_dic
if __name__ == ‘__main__‘:
file="介面測試案例.xls"
tag=‘BingdingCard‘
test_name="test_no_exist_cardnumber_bound"
test_list=excel_to_list(file,tag)
print(get_test_data(test_name,test_list))
python讀取execl資料檔案