def CleanStrForFilenames(filename):
    """Sanitize a string to be used as a filename"""
    keepcharacters = (' ', '.', '_')
    FILEOUT = "".join(c for c in filename if c.isalnum() or c in keepcharacters).rstrip()
    return FILEOUT