• 获取嵌套字典值的方法


    获取字典某一层的值

    """
            获取yaml文件中的字典value值,可获取字典值任意一层
            ele_dict = {
                'password_input':
                    {
                    'dec': '登录按钮', 
                    'type': 'XPATH', 
                    'value': '//button'
                    },
                'account_number_input':
                    {
                    'dec': '账号输入框', 
                    'type': 'CLASS_NAME', 
                    'value': 'ivu-input', 
                    'index': 0
                    },
            }
        """
        def get_value(self, *keys):
            """
            @param keys:yaml文件中的key值,可多层,['password_input','dec']或者['password_input']
            @return: 返回字典中value值
            """
            try:
                ele_dict = yaml.load(self.cfg, Loader=yaml.FullLoader)  # 用load方法转字典
                print(ele_dict)
                if not keys:
                    return ele_dict
                else:
                    for key in keys:
                        tmp = ele_dict.get(key)
                        if tmp is not None:
                            ele_dict = tmp
                    return ele_dict
            
    
        
  • 相关阅读:
    函数
    registry搭建及镜像管理-harbor
    用户输入和while 循环
    dockerfile
    字典,set
    if 语句
    alpine操作
    循环:列表,元组
    列表
    docker跨主机通信-overlay
  • 原文地址:https://www.cnblogs.com/lvchengda/p/12614313.html
Copyright © 2020-2023  润新知