zoukankan      html  css  js  c++  java
  • 如何写可配置文件

    工具类里放read_config.py方便以后调用

     1 import configparser
     2 
     3 
     4 class ReadConfig:
     5     # 参数化
     6     def read_config(self, filename, sections, button):
     7         cf = configparser.ConfigParser()
     8         cf.read(filename, encoding="utf-8")
     9         return cf.get(sections, button)
    10 
    11 
    12 if __name__ == '__main__':
    13     res = ReadConfig().read_config("case.config", "BUTTON", "button")
    14     print(res)

    在do_excel文件修改

        def get_data(self):
    
            wb = load_workbook(self.file_name)
            sheet = wb[self.sheet_name]
            test_data = []
            button = ReadConfig().read_config("case.config", "BUTTON", "button")
            for i in range(2, sheet.max_row+1):
                sub_data = {}
                sub_data['case_id'] = sheet.cell(i, 1).value
                sub_data['module'] = sheet.cell(i, 2).value
                sub_data['title'] = sheet.cell(i, 3).value
                sub_data['method'] = sheet.cell(i, 4).value
                sub_data['url'] = sheet.cell(i, 5).value
                sub_data['data'] = sheet.cell(i, 6).value
                sub_data['expected'] = sheet.cell(i, 7).value
                test_data.append(sub_data)  # 存储了所有的数据
                final_data = []
                if button == "all":
                    final_data = test_data
                else:
                    for item in test_data:
                        if item['case_id'] in eval(button):  # 记得这里进行数据类型转换
                            final_data.append(item)
            return final_data

    主要注意数据类型转换

    不用传参的方式,而是定义一个变量接收值

    button = ReadConfig().read_config("case.config", "BUTTON", "button")
  • 相关阅读:
    文件管理
    字符编码
    字典练习,统计字符串中单词出现次数
    字典有关练习:购物车
    列表及列表操作方法
    字符串及用法
    变量,程序交互,基本数据类型
    /usr/bin/ld: i386:x86-64 architecture of input file `command.o' is incompatible with i386 output
    混合云存储系统开发总结
    小记6月27
  • 原文地址:https://www.cnblogs.com/albeexu/p/12958120.html
Copyright © 2011-2022 走看看