Florin
Florin

Reputation: 4105

How to get the output of the built-in help() function in python in a string?

As a example :

>>> out = help(list) ## out must be a string .
>>> print out 
>>> ' Help on class list in module __builtin__:

class list(object)
 |  list() -> new empty list
 |  list(iterable) -> new list initialized from iterable's items '

Any advice highly appreciated ...

Upvotes: 0

Views: 113

Answers (2)

phihag
phihag

Reputation: 287885

import pydoc
pydoc.render_doc(list)

gives the whole output of help(list). If you're just interested in the top description (and not all methods defined on the object), use

list.__doc__

Upvotes: 4

fransua
fransua

Reputation: 1608

use the doc

print list.__doc__

Upvotes: 1

Related Questions