removing terminal control characters

yaipa h. yaipa at yahoo.com
Fri Sep 5 18:21:10 CEST 2003


Aaron,

Have a look at "Text Processing in Python," by David Mertz.
Wonderful book, just bought it from Amazon.com

Here is a link to the soft copy.
http://gnosis.cx/TPiP/

Cheers,

  --Alan

Aaron Kunkle <aaron at brokensociety.com> wrote in message news:<mailman.1062700444.27829.python-list at python.org>...
> 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
> 
> --




More information about the Python-list mailing list