def cast_int ( x ) : try : x = int ( x ) except ValueError : try : x = x . strip ( ) except AttributeError as e : logger_misc . warn ( "parse_str: AttributeError: String not number or word, {}, {}" . format ( x , e ) ) return x
how to make an input be recognized as an integer and string python
Cast unknown type into integer
def cast_int(x):
    """
    Cast unknown type into integer

    :param any x:
    :return int:
    """
    try:
        x = int(x)
    except ValueError:
        try:
            x = x.strip()
        except AttributeError as e:
            logger_misc.warn("parse_str: AttributeError: String not number or word, {}, {}".format(x, e))
    return x