def to_vartype(input, default=None, vartype=str):
    """
    Returns input converted to vartype or default if the conversion fails.

    Parameters
    ----------
    input : *
        Input value (of any type).
    default : *
        Default value to return if conversion fails.
    vartype : data type
        Desired data type. (default: string)

    Returns
    -------
    output : vartype or type(default)
        Input converted to vartype data type or default.
    """

    if vartype == bool and input == 'False': return False   # special custom case

    try:
        try:
            return vartype(input)
        except ValueError: return vartype(eval(input))
    except: return default