"""
    remove non-printable characters from line <line_p>
    return a printable string.
    """
line, i, imax = '', 0, len(line_p)
while i < imax:
    ac = ord(line_p[i])
if 32 <= ac < 127 or ac in (9, 10):
    line += line_p[i]
elif ac == 27:
    pass
Python regex to match VT100 escape sequences