Top-rated recipes tagged "introspection", "modules", "type" and "reflection"http://code.activestate.com/recipes/tags/introspection+modules+type+reflection/top/2016-10-06T17:21:42-07:00ActiveState Code RecipesGet names and types of all attributes of a Python module (Python)
2016-10-06T17:21:42-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580705-get-names-and-types-of-all-attributes-of-a-python-/
<p style="color: grey">
Python
recipe 580705
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/documentation/">documentation</a>, <a href="/recipes/tags/introspection/">introspection</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/reflection/">reflection</a>, <a href="/recipes/tags/type/">type</a>).
</p>
<p>This recipe shows how to get the names and types of all the attributes of a Python module. This can be useful when exploring new modules (either built-in or third-party), because attributes are mostly a) data elements or b) functions or methods, and for either of those, you would like to know the type of the attribute, so that, if it is a data element, you can print it, and if it is a function or method, you can print its docstring to get brief help on its arguments, processsing and outputs or return values, as a way of learning how to use it.</p>
<p>The code for the recipe includes an example call to it, at the end of the code.
Note that you first have to import the modules that you want to introspect in this way.</p>