def get_variables_by_attributes(self, **kwargs):
vs = []<EOL>has_value_flag  = False<EOL>for vname in self.variables:<EOL><INDENT>var = self.variables[vname]<EOL>for k, v in kwargs.items():<EOL><INDENT>if callable(v):<EOL><INDENT>has_value_flag = v(getattr(var, k, None))<EOL>if has_value_flag is False:<EOL><INDENT>break<EOL><DEDENT><DEDENT>elif hasattr(var, k) and getattr(var, k) == v:<EOL><INDENT>has_value_flag = True<EOL><DEDENT>else:<EOL><INDENT>has_value_flag = False<EOL>break<EOL><DEDENT><DEDENT>if has_value_flag is True:<EOL><INDENT>vs.append(self.variables[vname])<EOL><DEDENT><DEDENT>return vs<EOL>
Returns variables that match specific conditions.

        * Can pass in key=value parameters and variables are returned that
        contain all of the matches.  For example,

        >>> # Get variables with x-axis attribute.
        >>> vs = nc.get_variables_by_attributes(axis='X')
        >>> # Get variables with matching "standard_name" attribute.
        >>> nc.get_variables_by_attributes(standard_name='northward_sea_water_velocity')

        * Can pass in key=callable parameter and variables are returned if the
        callable returns True.  The callable should accept a single parameter,
        the attribute value.  None is given as the attribute value when the
        attribute does not exist on the variable. For example,

        >>> # Get Axis variables.
        >>> vs = nc.get_variables_by_attributes(axis=lambda v: v in ['X', 'Y', 'Z', 'T'])
        >>> # Get variables that don't have an "axis" attribute.
        >>> vs = nc.get_variables_by_attributes(axis=lambda v: v is None)
        >>> # Get variables that have a "grid_mapping" attribute.
        >>> vs = nc.get_variables_by_attributes(grid_mapping=lambda v: v is not None)