zoukankan      html  css  js  c++  java
  • python中异常处理

    #异常处理
    #1.让try的方位更广
    #读取excel为各种类型:列表,类
    import os
    import xlrd
    from pritices_daily import case_infos
    def read_excel_data_convert_info_01(excel_path):
    # 1,读取数据存到列表中:[[用例编号,用例名称,所在模块...],[....],[......]]
    try:
    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)
    except Exception as e:
    print('系统错误')
    return all_case_info1



    current_path = os.path.dirname(__file__)
    excel_path = os.path.join(current_path, '../111data/testcases.xlsx')
    print(read_excel_data_convert_info_01(excel_path))

    #2.看业务要求怎么定
    import os
    import xlrd
    from pritices_daily import case_infos
    def read_excel_data_convert_info_01(excel_path):
    # 1,读取数据存到列表中:[[用例编号,用例名称,所在模块...],[....],[......]]
    try:
    workbook = xlrd.open_workbook(excel_path)
    except FileNotFoundError as e: #文件路径错误再给一个默认的路径
    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)
    return all_case_info1

    current_path = os.path.dirname(__file__)
    excel_path = os.path.join(current_path, '../111data/testcases.xlsx')
    print(read_excel_data_convert_info_01(excel_path))

  • 相关阅读:
    O(1)时间求出栈内元素最小值 小强斋
    图片的轮廓 小强斋
    png 图片的缩放 小强斋
    Dom4j 小强斋
    O(1)时间求出栈内元素最小值 小强斋
    图片的轮廓 小强斋
    png图片的读取 小强斋
    字符串的最大重复数 小强斋
    【Android】数据的四种存储方式
    【就业】签offer和签三方协议的不同
  • 原文地址:https://www.cnblogs.com/tingting-yang/p/13267099.html
Copyright © 2011-2022 走看看