Popular recipes tagged "lazy" but not "generators"http://code.activestate.com/recipes/tags/lazy-generators/2014-12-03T09:55:06-08:00ActiveState Code RecipesEasy attribute setting and pretty representation (Python) 2014-12-03T09:55:06-08:00Joakim Petterssonhttp://code.activestate.com/recipes/users/4174760/http://code.activestate.com/recipes/578973-easy-attribute-setting-and-pretty-representation/ <p style="color: grey"> Python recipe 578973 by <a href="/recipes/users/4174760/">Joakim Pettersson</a> (<a href="/recipes/tags/attributes/">attributes</a>, <a href="/recipes/tags/lazy/">lazy</a>, <a href="/recipes/tags/traits/">traits</a>). Revision 2. </p> <p>Mix in one or more of these classes to avoid those tedious lines of administrative code for setting attributes and getting useful representations. </p> <p>If you inherit HasInitableAttributes, your should be able to obj = eval(repr(obj)) without loosing data.</p> <p>enthought.traits.api.HasTraits seems to mix in well also.</p> Recursively defined, Haskell-style infinite lists (Python) 2012-05-04T14:09:14-07:00John Crichtonhttp://code.activestate.com/recipes/users/4181975/http://code.activestate.com/recipes/578119-recursively-defined-haskell-style-infinite-lists/ <p style="color: grey"> Python recipe 578119 by <a href="/recipes/users/4181975/">John Crichton</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/functional/">functional</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/infinite/">infinite</a>, <a href="/recipes/tags/itertools/">itertools</a>, <a href="/recipes/tags/lazy/">lazy</a>, <a href="/recipes/tags/recursive/">recursive</a>). Revision 2. </p> <p>A decorator to simplify the creation of recursively defined, Haskell-style infinite lists -- ie. recursive generators -- inspired by Raymond Hettinger's "Technique for cyclical iteration" [*]. </p> <p>[*] <a href="http://code.activestate.com/recipes/576961-technique-for-cyclical-iteration/" rel="nofollow">http://code.activestate.com/recipes/576961-technique-for-cyclical-iteration/</a> </p> Super lazy load object (Python) 2010-03-16T05:02:12-07:00Russellhttp://code.activestate.com/recipes/users/4173357/http://code.activestate.com/recipes/577117-super-lazy-load-object/ <p style="color: grey"> Python recipe 577117 by <a href="/recipes/users/4173357/">Russell</a> (<a href="/recipes/tags/lazy/">lazy</a>). </p> <p>A really light implementation of lazy load technique, yet powerful and conveniet. </p> <p>Simply call this:</p> <pre class="prettyprint"><code>var1 = superlazy('key', default_value) </code></pre> <p>Your var1 will be loaded in load_setting(key) when accessed first time.</p> <p>That's it. No subclassing is needed, no declaration is needed. Value type is auto detected and handled gracefully. str, int, list, dict can all be lazily loaded from anywhere you want now.</p> lazy property (Python) 2009-04-26T18:10:55-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/576720-lazy-property/ <p style="color: grey"> Python recipe 576720 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/evaluation/">evaluation</a>, <a href="/recipes/tags/lazy/">lazy</a>, <a href="/recipes/tags/lazy_evaluation/">lazy_evaluation</a>). Revision 6. </p> <p>Python does not have lazy evaluation syntax features built-in, but fortunately decorators can be used with new-style classes to emulate such a feature. There are cases where one wants <code>foo.property</code> to return the actual property whose calculation takes significant amount of time.</p> <p>This recipe adapts the existing <code>property</code> to provide a <code>lazypropery</code> decorator that does this.</p> <p>See the first comment below for an example usage.</p> <p>Also see: <a href="http://en.wikipedia.org/wiki/Lazy_initialization">lazy initialization</a></p>