Latest recipes tagged "vars"http://code.activestate.com/recipes/tags/vars/new/2012-05-10T04:14:06-07:00ActiveState Code Recipes(Ab)Using Modules as Namespaces (Python) 2012-05-10T04:14:06-07:00Wolfgang Schererhttp://code.activestate.com/recipes/users/4182020/http://code.activestate.com/recipes/578122-abusing-modules-as-namespaces/ <p style="color: grey"> Python recipe 578122 by <a href="/recipes/users/4182020/">Wolfgang Scherer</a> (<a href="/recipes/tags/module/">module</a>, <a href="/recipes/tags/namespaces/">namespaces</a>, <a href="/recipes/tags/vars/">vars</a>). </p> <p>I have previously built a shar-like Python utility, which reads (marked) imported modules, gzips and base64 encodes them, then generates a python script, which is fully standalone.</p> <p>The included module source is placed into sys.modules at runtime, making imports possible without actually having the module files installed. A very nice thing for administrative scripts that have to work in unconfigured environments.</p> <p>At that time I discovered a lot of information about how modules in Python work.</p> <p>Reading the very interesting recipe at <a href="http://code.activestate.com/recipes/577887-a-simple-namespace-class/" rel="nofollow">http://code.activestate.com/recipes/577887-a-simple-namespace-class/</a> made me realize, that modules are actually very useful as generic namespaces too.</p>