Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   removing terminal control characters (http://www.velocityreviews.com/forums/t322039-removing-terminal-control-characters.html)

Aaron Kunkle 09-04-2003 03:18 AM

removing terminal control characters
 
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


yaipa h. 09-05-2003 04:21 PM

Re: removing terminal control characters
 
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@brokensociety.com> wrote in message news:<mailman.1062700444.27829.python-list@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
>
> --



All times are GMT. The time now is 09:54 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.