Removes any comments from a line.  A comment starts from a # symbol
    to the end of the line.  But don't remove from # symbol that are embedded
    in strings.

def _remove_comment(line):
    """
    Removes any comments from a line.  A comment starts from a # symbol
    to the end of the line.  But don't remove from # symbol that are embedded
    in strings.
    """
    # First find just quotes and their indexes.
    quote_indexes = []
    hash_indexes = []
    for i, ch in enumerate(line):
        if ch == '"':
            quote_indexes.append(i)
            if i > 0 and line[i - 1] == "\\":
                quote_indexes.pop()
        elif ch == '#':
            hash_indexes.append(i)

    comment_marker_index = -1
    for hash_index in hash_indexes:
        quote_index_ranges = [quote_indexes[i:i + 2] for i in range(0, len(quote_indexes), 2)]
        if not _check_index_within_index_pairs(hash_index, quote_index_ranges):
            comment_marker_index = hash_index
            break

    if comment_marker_index >= 0:
        line = line[:comment_marker_index]
    return line