def _check_list(value, temp_list, var_name=None):
    """
    Helper function to test if a value exists within a list. 
    If not, then raise ValueError exception.
    This is mainly used for limiting the allowed values of some variable.
    """
    if value not in temp_list:
        if None in temp_list:
            temp_list[temp_list.index(None)] = 'None'
        var_name = '' if var_name is None else var_name + ' '
        err_str = 'Invalid {}setting: {} \n\tValid values are: {}'.format(
            var_name, value, ', '.join(temp_list))
        raise ValueError(err_str)
