Python: How to store the documentation (help) of a class in a String?

3

I'm doing an explorer explorer of classes in Python. Can I store class methods and attributes with

 dir(obj) 

and place them in a TreeView. I would like to display the references of this when clicked. For this I would use the

 help(obj)

of the class in question. For this I would need the text stored in a String, and thus locate references about it with

 String.find(nome_do_atributo)

The problem is, that when I call help (obj), it prints the text in the outuput. Does anyone know how to make help (obj) text stored in a variable, instead of being printed on the system output?

    
asked by anonymous 13.12.2016 / 23:12

1 answer

0

Sorry for my barbeiragem, but I was able to find the solution.

First, you need to import pydoc

import pydoc

In Python 3:

string_help = pydoc.render_doc(nome_da_classe, renderer=pydoc.plaintext)

And if the class name comes as string:

string_help = pydoc.render_doc(eval("nome_da_classe"), renderer=pydoc.plaintext)

Caution: eval has its risks because it executes anything !!!

In Phython 2, I did not try, but they say it's like this, I'll pass it in good faith, if it does not work, let me know.

 string_help = pydoc.plain(pydoc.render_doc(nome_da_classe))

I hope you help.

    
14.12.2016 / 01:51