Popular recipes tagged "meta:requires=importlib" and "import"http://code.activestate.com/recipes/tags/meta:requires=importlib+import/2011-08-12T23:39:58-07:00ActiveState Code RecipesApply decorators to all functions in a module (Python)
2011-06-09T22:51:28-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577742-apply-decorators-to-all-functions-in-a-module/
<p style="color: grey">
Python
recipe 577742
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/import/">import</a>, <a href="/recipes/tags/modules/">modules</a>).
Revision 2.
</p>
<p>Use my modulehacker recipe (<a href="http://code.activestate.com/recipes/577740/">recipe 577740</a>) to apply decorators to any number of modules, or even (nearly) all of them.</p>
Use Simple Plugins to Seemlessly Modify Modules at Import Time (Python)
2011-07-12T18:55:18-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577740-use-simple-plugins-to-seemlessly-modify-modules-at/
<p style="color: grey">
Python
recipe 577740
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/import/">import</a>, <a href="/recipes/tags/modules/">modules</a>).
Revision 4.
</p>
<p>This recipe uses the PEP 302 import hooks to expose all imported modules to devious behavior.</p>
<p>Simply put, the module is imported like normal and then passed to a hacker object that gets to do whatever it wants to the module. Then the return value from the hack call is put into sys.modules.</p>
<p><a href="http://code.activestate.com/recipes/577741/">Recipe 577741</a> and <a href="http://code.activestate.com/recipes/577742/">recipe 577742</a> are more concrete examples of using this recipe.</p>
Turn Your Boring Old Modules Into Dynamic Powerhouses (Python)
2011-08-12T23:39:58-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577741-turn-your-boring-old-modules-into-dynamic-powerhou/
<p style="color: grey">
Python
recipe 577741
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/import/">import</a>, <a href="/recipes/tags/modules/">modules</a>).
Revision 2.
</p>
<p>Customize your module objects by using this recipe! </p>
<p>All you have to do is import the module containing this code, register the custom module class you want, and stick __moduleclass__ the module that you want customized. The example should explain it all.</p>
<p>This recipe uses <a href="http://code.activestate.com/recipes/577740/">recipe 577740</a>.</p>