def replace_text_comment(comments, new_text):
    """Replace "# text = " comment (if any) with one using new_text instead."""
    new_text = new_text.replace('\n', ' ')    # newlines cannot be represented
    new_text = new_text.strip(' ')
    new_comments, replaced = [], False
    for comment in comments:
        if comment.startswith('# text ='):
            new_comments.append('# text = {}'.format(new_text))
            replaced = True
        else:
            new_comments.append(comment)
    if not replaced:
        new_comments.append('# text = {}'.format(new_text))
    return new_comments