The method of obtaining the value of nested dictionaries

Gets the value of a layer of the dictionary

"" " 
        Get value yaml dictionary file value, any one can obtain the value of the dictionary 
        ele_dict = { 
            'password_input': 
                { 
                'On Dec': 'login button', 
                'type': 'XPATH', 
                'value': '/ / Button ' 
                }, 
            ' account_number_input ': 
                { 
                ' On Dec ':' account input box ', 
                ' type ':' CLASS_NAME ', 
                ' value ':' IVU-iNPUT ', 
                ' index ': 0 
                }, 
        } 
    "" " 
    DEF get_value (self,*keys):
        """
        @param keys: key value yaml file, can be multilayer, [ 'password_input', 'dec '] or [ 'password_input'] 
        @return: Returns the value of the dictionary value 
        "" " 
        the try : 
            ele_dict = yaml.load (Self .cfg, Loader = yaml.FullLoader)   # turn dictionaries with load method 
            Print (ele_dict)
             IF  not Keys:
                 return ele_dict
             the else :
                 for Key in Keys: 
                    tmp = ele_dict.get (Key)
                     IF tmp IS  not None: 
                        ele_dict = tmp
                return ele_dict
        

    

 

Guess you like

Origin www.cnblogs.com/lvchengda/p/12614313.html