removing terminal control characters

Aaron Kunkle aaron at brokensociety.com
Wed Sep 3 23:18:20 EDT 2003


i'm trying to display output from a linux command line program and i'm
getting a lot of junk.
i was told that pulling out escape sequences like this regex: \033[^;]*;
would do it but that doesnt catch them all. i'm seeing the little box
characters for instance.

the only way i've found thus far is this:

building the regex object:
    regex = re.compile(r'\033[^;]*;')
then passing each line of output through this:
    line = regex.sub("",line)
    junk = line.translate(identity, string.printable)
    line = line.translate(identity, junk)

i know there must be a better way!
is there a way to get a non-printable group of characters to search
for?  

thanks,
aaron kunkle
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20030903/3f2403ce/attachment.html>


More information about the Python-list mailing list