Popular recipes tagged "modules" but not "import"http://code.activestate.com/recipes/tags/modules-import/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>
Clear Only Project Modules (Python)
2014-12-17T19:03:15-08:00Cornelius Jatniel Prinsloohttp://code.activestate.com/recipes/users/4191358/http://code.activestate.com/recipes/578982-clear-only-project-modules/
<p style="color: grey">
Python
recipe 578982
by <a href="/recipes/users/4191358/">Cornelius Jatniel Prinsloo</a>
(<a href="/recipes/tags/clear/">clear</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/project/">project</a>, <a href="/recipes/tags/reload/">reload</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/startup/">startup</a>).
</p>
<p>Useful for python sessions that have a long startup time
because of external dependancies
[In my case that would be pygame and pymunk]
I've got a slow computer so it takes a while to startup
this is the solution I came up with</p>
<p>import this before any other of your project imports
example:
import reloading # The modules in your project folder get cleared
then load the rest of your project modules</p>
<p>make sure that the reloading script is in your project folder, or else it won't work</p>
<p>You might be able to extend this by changing line</p>
Trace decorator for debugging (Python)
2011-01-24T18:40:51-08:00Kevin L. Sitzehttp://code.activestate.com/recipes/users/4173535/http://code.activestate.com/recipes/577551-trace-decorator-for-debugging/
<p style="color: grey">
Python
recipe 577551
by <a href="/recipes/users/4173535/">Kevin L. Sitze</a>
(<a href="/recipes/tags/classes/">classes</a>, <a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/functions/">functions</a>, <a href="/recipes/tags/inspection/">inspection</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/trace/">trace</a>).
Revision 2.
</p>
<p>This package provides a decorator for tracing function and method calls in your applications. The tracing capabilities are managed through the logging package, and several mechanisms are provided for controlling the destination of the trace output.</p>
<p>It also provides functionality for adding decorators to existing classes or modules.</p>
Open a python module given it's name in Emacs (Bash)
2010-07-19T10:25:06-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577317-open-a-python-module-given-its-name-in-emacs/
<p style="color: grey">
Bash
recipe 577317
by <a href="/recipes/users/4173873/">Noufal Ibrahim</a>
(<a href="/recipes/tags/emacs/">emacs</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python_developer_tools/">python_developer_tools</a>, <a href="/recipes/tags/zsh/">zsh</a>).
</p>
<p>A tiny little <code>zsh</code> function to open a python module in <code>Emacs</code>. Assumes that an <code>Emacs</code> server process is running. </p>
PluginManager - Extending Project Functionality By Using Custom Modules/Plugins On The Fly. (Python)
2010-05-07T15:32:10-07:00AJ. Mayorgahttp://code.activestate.com/recipes/users/4173476/http://code.activestate.com/recipes/577216-pluginmanager-extending-project-functionality-by-u/
<p style="color: grey">
Python
recipe 577216
by <a href="/recipes/users/4173476/">AJ. Mayorga</a>
(<a href="/recipes/tags/extending/">extending</a>, <a href="/recipes/tags/extensible/">extensible</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/plugin/">plugin</a>).
Revision 4.
</p>
<p>This demo shows how you can create and manage your own custom plugins for extending functionality in your Python projects. There are no safety wrappers in this demo for restricting plugins aside from that fact that plugins are run as an extention of a management class which is run in its own instance only receiving data passed to it by the RumModules method, that said security should ideally be applied to the ModuleAPI class, by restricting __builtins__ on eval calls and/or validating plugin content and parameters which can be done by extending the Prepaser Class. For a great recipe/demo of restricting eval call see <a href="http://code.activestate.com/recipes/496746" rel="nofollow">http://code.activestate.com/recipes/496746</a>. </p>
<p>That aside it was alot of fun to write and use. Enjoy</p>
<p>PS: you will need <a href="http://code.activestate.com/recipes/577144/" rel="nofollow">http://code.activestate.com/recipes/577144/</a> to import Xceptions</p>
Temporary substitution of object in modules via with statement (Python)
2010-01-24T04:19:12-08:00Jacob Oscarsonhttp://code.activestate.com/recipes/users/1355144/http://code.activestate.com/recipes/577020-temporary-substitution-of-object-in-modules-via-wi/
<p style="color: grey">
Python
recipe 577020
by <a href="/recipes/users/1355144/">Jacob Oscarson</a>
(<a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/testing/">testing</a>, <a href="/recipes/tags/with_statement/">with_statement</a>).
</p>
<p>See docstring in the code</p>
Getting version number of modules (Python)
2008-09-06T05:28:46-07:00Kaushik Ghosehttp://code.activestate.com/recipes/users/4166965/http://code.activestate.com/recipes/576491-getting-version-number-of-modules/
<p style="color: grey">
Python
recipe 576491
by <a href="/recipes/users/4166965/">Kaushik Ghose</a>
(<a href="/recipes/tags/modules/">modules</a>).
</p>
<p>How to print out the version number of a module</p>