Popular recipes tagged "closure"http://code.activestate.com/recipes/tags/closure/popular/2012-07-24T09:51:48-07:00ActiveState Code RecipesSimple tool for simulating classes using closures and nested scopes (Python) 2012-04-11T06:21:18-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/578091-simple-tool-for-simulating-classes-using-closures-/ <p style="color: grey"> Python recipe 578091 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/closure/">closure</a>, <a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/oriented/">oriented</a>). Revision 9. </p> <p>Closured-based alternative to normal classes. Allows a faster, cleaner coding style at the expense of some functionality.</p> A Python decorator that re-executes the function on condition (Python) 2012-07-24T09:51:48-07:00Chaobin Tang (唐超斌)http://code.activestate.com/recipes/users/4174076/http://code.activestate.com/recipes/578222-a-python-decorator-that-re-executes-the-function-o/ <p style="color: grey"> Python recipe 578222 by <a href="/recipes/users/4174076/">Chaobin Tang (唐超斌)</a> (<a href="/recipes/tags/closure/">closure</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/retry/">retry</a>). Revision 3. </p> <p>Sometimes we want a function to be able to be retried automatically, such as a function that does networking trying to write/read data through a pre-established connection. Instead of writing try/except everywhere, a decorator would save much code and provide a single copy of code to do all the work.</p> Run async code inline, nonblocking (Python) 2011-11-23T10:13:31-08:00PRITAM Khttp://code.activestate.com/recipes/users/4180048/http://code.activestate.com/recipes/577959-run-async-code-inline-nonblocking/ <p style="color: grey"> Python recipe 577959 by <a href="/recipes/users/4180048/">PRITAM K</a> (<a href="/recipes/tags/asynchronous/">asynchronous</a>, <a href="/recipes/tags/closure/">closure</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/threads/">threads</a>). </p> <p>A decorator, that makes it easy to switch between the mainthread and background threads.</p> Change a Function's Closure! (Python) 2011-08-12T23:25:55-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577760-change-a-functions-closure/ <p style="color: grey"> Python recipe 577760 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/closure/">closure</a>, <a href="/recipes/tags/function/">function</a>). Revision 2. </p> <p>This is a hack to get around the read-only nature of __closure__ on function objects. Watch your step!</p> Run async code inline, nonblocking (Python) 2009-11-11T12:55:01-08:00Thomas Ahlehttp://code.activestate.com/recipes/users/4060075/http://code.activestate.com/recipes/576952-run-async-code-inline-nonblocking/ <p style="color: grey"> Python recipe 576952 by <a href="/recipes/users/4060075/">Thomas Ahle</a> (<a href="/recipes/tags/asynchronous/">asynchronous</a>, <a href="/recipes/tags/closure/">closure</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/threads/">threads</a>). Revision 7. </p> <p>A decorator, that makes it easy to switch between the mainthread and background threads.</p>