import logging


def saveData(fileName, data):
    """Save data to persistent file. If file does not already exist it will
    be created. The function will return True if successful, else False.

    :param fileName: Name of the file to save to.
    :type fileName: string
    :param data: The data object to save
    :type data: var
    :return: Status. True if successful, False if unsuccessful.
    :rtype: bool
    """
    try:
        with open(fileName, 'w', encoding='utf-8') as f:
            f.write(data)
    except Exception as e:
        logger = logging.getLogger('discord')
        logger.warning(
            'Exception thrown when trying to serialize data. '
            'Error message reads as follows:\n'
            f'{e}\n'
        )
        return False
    return True