How to list the class synopsis?

7

I started to venture into python and am doing program that lists the properties of the classes. I use the obj dic , the help (obj), and the dir (obj). Does anyone know if there is a command that lists the synopses of the methods, something like this:

For example for a Gtk.Box, how can I get a result similar to this?

  pack_start(child, expand=True, fill=True, padding=0)
  pack_end(child, expand=True, fill=True, padding=0)
  pack_start_defaults(widget)
  pack_end_defaults(widget)
  pack_end_defaults(widget)
    
asked by anonymous 13.12.2016 / 06:54

1 answer

2

As it is in the comments - the text that is displayed when asking for help in Python is what is defined in the modules, classes or functions as "docstring" - it is available as the __doc__ attribute of the object in question, and is automatically created if the first expression inside the body of a module, class, or function (including method) is a string:

In [6]: import math

In [7]: math.sin.__doc__
Out[7]: 'sin(x)\n\nReturn the sine of x (measured in radians).'

However, objects do not always include a meaningful docstring - and it is not always enough. The Python help for classes, for example, joins all method declarations, and the docstrings of each other, in addition to the docstring of the class.

Internally, help uses the pydoc module, and inside it, the function that retrieves the full text of the help is called render_doc .

Therefore:

>>> import gtk
>>> import pydoc
>>> text = pydoc.render_doc(gtk.Box)
>>> print (text)
...

However - even the enderdoc does not retrieve the signature of the functions that are written in C, or if they use the * args, ** kwargs feature. This is the case for most PyGTK functions - so it is not possible to get an output like the one you ask for.

    
18.01.2017 / 20:06