def split_trailing_comment(line, comment_char = '!'):
    """Returns a pair of strings: (line stripped of trailing comment, trailing comment)."""
    # also removes trailing newline
    comment = ''
    local_line = line
    while len(local_line) > 0 and local_line[-1] in ['\n', '\r']:
        local_line = local_line[:-1]
    try:
        pling = local_line.index(comment_char)
        if pling < len(local_line) - 2:
            comment = local_line[pling + 1:]
        return (local_line[:pling], comment)
    except Exception:
        return (local_line, '')