接口自动化-- do——excel pandas 改造
from tools.read_config import ReadConfig from tools import project_path from tools.get_data import GetData import pandas as pd class DoExcel: def get_data(self,file_name): df = pd.ExcelFile(file_name) #8,9 是获取表格里的sheetname,结果为一个列表 sheets = df.sheet_names for sheet in sheets: #将sheet名循环,读取每一个sheet df = pd.read_excel(file_name,sheet_name=sheet) mode = eval(ReadConfig().get_config(project_path.case_config_path,"MODE","mode")) test_data=[] for key in mode: # sheet = wb[key] if mode[sheet] ==‘all‘: for i in df.index.values: #df.index.values为sheet的行号列表 row_data = df.loc[i].to_dict() #循环读取每行的数据并转化为字典 test_data.append(row_data) #将字典放入列表 else: for case_id in mode[sheet]: row_data=df.loc[case_id].to_dict() test_data.append(row_data) return test_data if __name__ == ‘__main__‘: do_excel = DoExcel() test_data = do_excel.get_data(r"D:\BaiduNetdiskDownload\NMB_API_61\test_data\test_data.xlsx") print(test_data)
参考 :https://www.jb51.net/article/166820.htm
相关推荐
三石 2020-10-30
roamer 2020-10-29
三石 2020-10-29
wangquannuaa 2020-10-15
wangquannuaa 2020-09-29
jzlixiao 2020-09-15
wangquannuaa 2020-08-30
三石 2020-08-23
逍遥友 2020-08-21
jzlixiao 2020-08-18
wangquannuaa 2020-08-17
QianYanDai 2020-08-16
cjsyrwt 2020-08-14
jzlixiao 2020-07-29
xirongxudlut 2020-07-20
mmmjyjy 2020-07-16
QianYanDai 2020-07-05
QianYanDai 2020-07-05
june0 2020-07-04