How to use pydoc to generate a list of methods and properties in a Python file
Question: I have some classes that I wrote, and in some of them I did add some docs
strings, like in the class header.

Now I would like to use pydoc, to generate documentation, but I realized that
pydoc won't print anything unless I actually write the doc part inside the
class, which is not what I want.

Is there a way to have pydoc generate a list of all the properties, methods
and their type, including the type of the parameter required (if any), and the
type of the return (if any)?

If I have a class like this:

    
    
    class myclass(object):
    
        def __init__(anumber=2, astring="hello"):
            self.a = anumber
            self.b = astring
    
        def printme(self):
            thestring = self.a + self.b + "\nthat's all folks\n"
            return thestring
    
        def setvalues(self, a_number, a_string):
            self.a = a_number
            self.b = a_string
    

I would like to print something that includes the class name, class method,
datatype:

    
    
    class name
    what parameters it takes in the init and the type of the parameters
    
    method name
    what parameters it takes and the type of the parameters
    what value return and its type.
    

I believe pydoc won't do that. Is there any other way to do so?

I can add the doc strings for explanation later, but first of all, I would
like to print out what is in my modules, to know what it takes, what it
returns and so on.


Answer: Pydoc should provide you the skeleton details, the same as `help(myclass)`,
this will show you the function signatures of your class without any
docstrings. You can use pydoc module to get this help information:

    
    
    $ pydoc MyClass.myclass
    Help on class myclass in MyClass:
    
    class myclass(builtins.object)
     |  Methods defined here:
     |  
     |  __init__(anumber=2, astring='hello')
     |  
     |  printme(self)
     |  
     |  setvalues(self, a_number, a_string)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
    

You can do this programmatically with the `pydoc` module:

    
    
    >>> import pydoc
    >>> import MyClass
    >>> h = pydoc.plain(pydoc.render_doc(MyClass))
    >>> print h
    

