Python读取Excel测试用例时出现list index out of range错误该如何解决?

python读取excel测试用例时引发list index out of range错误

在使用python处理excel文件时,经常会遇到各种问题。本文将针对一个常见的错误——list index out of range——进行分析和解答,该错误发生在读取excel测试用例的过程中。

问题描述:程序员使用xlrd库读取excel文件中的测试用例,代码旨在根据用例名称找到对应的请求数据和返回数据,并将它们存储在一个列表中。然而,在运行过程中,程序抛出了list index out of range异常。

出错代码片段如下:

import xlrddef get_excel(info,sheetname,casename):    testcase_excel = xlrd.open_workbook(info,formatting_info=true)    testcase = testcase_excel.sheet_by_name(sheetname)    response_list = []    indx = 0    for one in testcase.col_values(0):        if casename in one:            requests_body = testcase.cell_value(indx, 4)  # 获取sheet表中的请求数据            response_data = testcase.cell_value(indx, 5)  # 获取sheet表中的返回数据            response_list.append((requests_body,response_data))        indx += 1    return response_listif __name__ == '__main__':    res = get_excel('../data/python测试用例.xls','登录','login')    print(res)

登录后复制

本文来自互联网或AI生成,不代表软件指南立场。本站不负任何法律责任。

如若转载请注明出处:http://www.down96.com/tutorials/13181.html

热心网友热心网友
上一篇 2025-04-11 17:12
下一篇 2025-04-11 17:12

相关推荐

本站[软件指南]所有内容来自互联网投稿或AI智能生成,并不代表软件指南的立场。