Unescaping formatted Terminal text

G

Gnarlodious

This may be happening because I am using Python 3.2 which includes
"curses" to format output. When running:

pydoc.render_doc(sys.modules[__name__])

in Terminal I see FUNCTIONS

when the same output goes to HTTP I see FFUUNNCCTTIIOONNSS

Is there an easy way to strip ANSI escaped characters from output for
CGI rendering?

-- Gnarlodious
 
P

Peter Otten

Gnarlodious said:
This may be happening because I am using Python 3.2 which includes
"curses" to format output. When running:

pydoc.render_doc(sys.modules[__name__])

in Terminal I see FUNCTIONS

when the same output goes to HTTP I see FFUUNNCCTTIIOONNSS

What you are seeing isn't an ANSI escape sequence, it's actually Char-
Backspace-Char (e. g. "F\bF\U\bU...") which is interpreted as a bold Char by
the "less" utility.
Is there an easy way to strip ANSI escaped characters from output for
CGI rendering?

pydoc.render_doc(module, renderer=pydoc.plaintext)

or even

pydoc.render_doc(module, renderer=pydoc.html)
 
G

Gnarlodious

Thanks, it looks like the appropriate incantation is:

import pydoc
pydoc.html.docmodule(sys.modules[__name__])

-- Gnarlie
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top