Python使用第三方庫xlrd讀取Excel
介面自動化測驗中,資料和代碼分離才能邏輯更清晰,所以用excel管理用例資料比較方便
一、安裝xlrd
pip install xlrd
二、使用命令
#coding=utf-8
import xlrd
wb=xlrd.open_workbook("test_user_data.xls") #打開excel
sh=wb.sheet_by_name("TestUserLogin") #按表格名稱獲取表格
print(sh.nrows) #獲取有效的資料行數
print(sh.ncols) #獲取有效的資料列數
print(sh.cell(0,0).value) #獲取單元格值
print(sh.row_values(0)) #獲取第一行資料
print(dict(zip(sh.row_values(0),sh.row_values(1)))) #將表頭和資料整理成字典
for i in range(1,sh.nrows):
zipdata=https://www.cnblogs.com/testerlina/p/dict(zip(sh.row_values(0),sh.row_values(i)))
print zipdata
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/115623.html
標籤:Python
下一篇:用post請求制作翻譯
