def from_string ( cls , string ) : # find enum value for attr in dir ( cls ) : value = getattr ( cls , attr ) if value == string : return value # if not found, log warning and return the value passed in logger . warning ( "{} is not a valid enum value for {}." . format ( string , cls . __name__ ) ) return string
python if string in enum
Simply logs a warning if the desired enum value is not found .
def from_string(cls, string):
        """
        Simply logs a warning if the desired enum value is not found.

        :param string:
        :return:
        """

        # find enum value
        for attr in dir(cls):
            value = getattr(cls, attr)
            if value == string:
                return value

        # if not found, log warning and return the value passed in
        logger.warning("{} is not a valid enum value for {}.".format(string, cls.__name__))
        return string