from datetime import datetime


def get_tag(tag=None):
    """
    Simple helper function to create a tag for saving a file if one does not already exist.

    This is useful because in some places we don't know whether we will have a tag or not,
    but still want to save files.

    Parameters
    ----------
    tag : string or None (optional)
      Name of file if it already exists

    Returns
    ----------
    tag : string or None (optional)
      Name picked for the file
    """

    # Get the data and time in a file-saving--friendly format
    date_time = datetime.now().strftime("%m_%d_%Y_%H_%M_%S")

    # If there is no tag, use the date and time
    tag = date_time if tag is None else tag

    return tag