def cast_type(obj, *types):
    """
    Attempts to cast object to type. If first type fails, goes through args attempting all given types.

    :param obj: Object to cast to type
    :param types: Types to attempt
    :returns: Object in new type, if converted. Otherwise raises TypeError
    """
    if type(obj) in types:
        return obj
    for t in types:
        try:
            return t(obj)
        except Exception:
            pass
    raise TypeError('Failed to typecast {!r} to {}'.format(obj, ', '.join([
        repr(t) for t in types])))
