Top-rated recipes tagged "namespaces"http://code.activestate.com/recipes/tags/namespaces/top/2013-02-14T17:42:24-08:00ActiveState Code RecipesA Simpler Namespace Class (Python) 2013-02-14T17:42:24-08:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/578141-a-simpler-namespace-class/ <p style="color: grey"> Python recipe 578141 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/namespaces/">namespaces</a>, <a href="/recipes/tags/object/">object</a>). Revision 3. </p> <p>A very simple, attribute-based namespace type (and one offspring). Everyone's written one of these...</p> (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> Javascript Namespaces (JavaScript) 2009-07-12T07:21:40-07:00Mike Kosshttp://code.activestate.com/recipes/users/4171086/http://code.activestate.com/recipes/576839-javascript-namespaces/ <p style="color: grey"> JavaScript recipe 576839 by <a href="/recipes/users/4171086/">Mike Koss</a> (<a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/namespaces/">namespaces</a>). Revision 2. </p> <p>This recipe enables you to modularize javascript libraries by placing all library code within a namespace object. All namespaces are rooted at "window.global_namespace". References between namespaces are supported by the Import function, which allows forward references to namespaces that have yet to be defined.</p> <p>See code comment for more detailed examples.</p> A Simple Namespace Class (Python) 2011-10-03T21:12:41-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577887-a-simple-namespace-class/ <p style="color: grey"> Python recipe 577887 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/dict/">dict</a>, <a href="/recipes/tags/namespaces/">namespaces</a>). Revision 3. </p> <p>"Namespaces are one honking great idea -- let's do more of those!" -- <a href="http://www.python.org/dev/peps/pep-0020/">The Zen of Python</a></p> <p>For when you want a simple, easy namespace, but you don't want it cluttered up with Python's object machinery.</p>