I'm trying to use pydoc.render_doc(object) to get the help documentation on an object as a string. However for some reason, doing so makes all the method names of the given object show up very strange; every other character is '\x08' and letters are grouped by two. For example, __new__ ____nneeww____ ('\x08' doesn't render here for some reason). Any ideas on what could be causing the problem?
1 Answer
pydoc has to be pretty ancient module.
pydoc makes noise of mechanical printer
The \x08 character is backspace and what I saw made me smile for a moment:
>>> pydoc.render_doc(object)
'Python Library Documentation: class object in module __builtin__\n\nclass o\x08ob\x08bj\x08je\x08ec\x08ct\x08t\n | The most base type\n'
It seems, like the default expectation of this module is to print the output to real mechanical printer.
There the backspace causes the carriage to move one character back, and the repeated characters are there to print it once more over backspaced position.
This could result in having it printed bold on mechanical printer.
If you want to get rid of this special decorations, use pydoc.plain:
>>> pydoc.plain(pydoc.render_doc(object))
'Python Library Documentation: class object in module __builtin__\n\nclass object\n | The most base type\n'
A bit of history (2001)
Python stdlib doc claims, pydoc is New in version 2.1.
Wikipedia claims, the Python 2.1 was released April 17, 2001