Getting all the attributes reachable from a module or any other object
<p>Consider this:</p>

<pre><code>&gt;&gt;&gt; import math
&gt;&gt;&gt; dir(math)
['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'hypot', 'isinf', 'isnan', 'ldexp', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
</code></pre>

<p><code>__dict__</code> is not listed but I can still do</p>

<pre><code>&gt;&gt;&gt; math.__dict__
</code></pre>

<p>Same thing with</p>

<pre><code>&gt;&gt;&gt; class MyClass(object):
         def __init__(self, var1, var2):

             self.a = var1
             self.b = var2

         def __call__(self, arg):

             print " The arg passed is ", arg

&gt;&gt;&gt; dir(MyClass) 

['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
</code></pre>

<p><code>__bases__</code> and <code>__base__</code> is not listed but I can still do:</p>

<pre><code>&gt;&gt;&gt; MyClass.__bases__
(&lt;type 'object'&gt;,)
&gt;&gt;&gt; MyClass.__base__
&lt;type 'object'&gt;
</code></pre>

<p>Question:</p>

<p>How can I know or tell in advance all the attributes reachable from a python object? In this case how can I tell that <code>math</code> module has <code>__dict__</code> and <code>MyClass</code> has <code>__base__</code> and <code>__bases__</code> ?</p>
