removing terminal control characters

A

Aaron Kunkle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top