Getting docstrings from Python package __init__ - based imports
<p>I have several modules that are within a Python package:</p>

<pre><code># my_package contents
__init__.py
module1.py
module2.py
</code></pre>

<p>Within my <code>__init__.py</code>, I'm importing these modules so that they will be accessible once the package is imported by my users.</p>

<pre><code># __init__.py
import module1
import module2
</code></pre>

<p>My question is:  how do I programatically access the docstrings for each of my defined functions within each of these modules?  I've seen <a href="http://stackoverflow.com/a/1270639/655787">others</a> use a form of this:</p>

<pre><code>getattr(module, key). __doc__
</code></pre>

<p>but I can't get it to work for me.  Any ideas?</p>

<p>EDIT: A little more background... we're trying to extract content (one of the important things is the docstrings) from our python packages with the intent of using that as content for documentation.  My boss has something already set up that we're trying to feed into.</p>

<p>Ideally, I'd like to have a <code>package.module.function docstring</code> result</p>

<p>EDIT2:  Here's what is currently <strong>not</strong> working:</p>

<pre><code>#my package is named 'tpp'
import tpp

for script in dir(tpp):
    if not "__" in script: #not a builtin...
        docstrings1 = getattr( tpp, script).__doc__
        docstrings2 = " ".join(docstrings1.split())#clean out any newline chars
        print script, docstrings
</code></pre>

<p>EDIT3:  To get a picture of where the docstrings are and how we've organized things:</p>

<pre><code>import inspect
import tpp

inspect.getdoc(tpp)
#returns None

inspect.getdoc(tpp.module1)
#returns None

inspect.getdoc(tpp.module1.function1)
#'DOCSTRING TEXT FOUND!'
</code></pre>

<p>**Ultimately, I'd like to get a list like ['module1', 'function1', 'DOCSTRING TEXT FOUND!']</p>
