Most viewed recipes tagged "parameters"http://code.activestate.com/recipes/tags/parameters/views/2012-04-18T06:13:25-07:00ActiveState Code RecipesSingleton (parameter based) (Python) 2012-04-18T06:13:25-07:00Thomas Lehmannhttp://code.activestate.com/recipes/users/4174477/http://code.activestate.com/recipes/578103-singleton-parameter-based/ <p style="color: grey"> Python recipe 578103 by <a href="/recipes/users/4174477/">Thomas Lehmann</a> (<a href="/recipes/tags/parameters/">parameters</a>, <a href="/recipes/tags/singleton/">singleton</a>). Revision 3. </p> <p><strong>Why?</strong></p> <ul> <li>There are many recipes but nearly all cover the global singleton only.</li> <li>I need a singleton which can handle things in a specific context (environment).</li> </ul> <p><strong>The final singleton is a combination of following two recipes</strong>:</p> <ul> <li><a href="http://www.python.org/dev/peps/pep-0318/#examples" rel="nofollow">http://www.python.org/dev/peps/pep-0318/#examples</a></li> <li><a href="http://stackoverflow.com/a/9489387" rel="nofollow">http://stackoverflow.com/a/9489387</a></li> </ul> <p><strong>The basic advantages</strong>:</p> <ul> <li>Hiding the singleton code by a simple decorator</li> <li>Flexible, because you can define fully global singletons or parameter based singletons.</li> </ul> <p><strong>Latest changes</strong>:</p> <ul> <li>Although a function/method does not have parameters you can call it with parameters <strong>args</strong> and <strong>kwargs</strong> as you now see in the <strong>getInstance</strong> function.</li> <li>...</li> </ul>