Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > removing terminal control characters

Reply
Thread Tools

removing terminal control characters

 
 
Aaron Kunkle
Guest
Posts: n/a
 
      09-04-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

 
Reply With Quote
 
 
 
 
yaipa h.
Guest
Posts: n/a
 
      09-05-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 <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
>
> --

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal' Steve Python 2 12-07-2010 05:48 PM
open a new terminal window from another terminal window in linux/unixsystem gaurav kashyap Python 3 10-31-2008 12:10 PM
Help with cleaning input text - removing control characters Peter O'Reilly Javascript 8 08-07-2004 06:37 AM



Advertisments