Popular Python recipes tagged "meta:requires=opcode"http://code.activestate.com/recipes/langs/python/tags/meta:requires=opcode/2014-10-05T04:10:21-07:00ActiveState Code Recipeswhere() function for generator expressions (Python 3) (Python) 2014-10-05T04:10:21-07:00Alan Cristhian Ruizhttp://code.activestate.com/recipes/users/4186199/http://code.activestate.com/recipes/578946-where-function-for-generator-expressions-python-3/ <p style="color: grey"> Python recipe 578946 by <a href="/recipes/users/4186199/">Alan Cristhian Ruiz</a> (<a href="/recipes/tags/generators/">generators</a>). Revision 3. </p> <p>Function that work like an "where statement" for generator expression. The code below</p> <pre class="prettyprint"><code>x, y, z = 1, 2, 3 ((x, y, z) for _ in range(5)) </code></pre> <p>Is equivalent to:</p> <pre class="prettyprint"><code>((x, y, z) for _ in range(5)) &lt; where(x=1, y=2, z=3) </code></pre> (Yet another) Assignment in expression Recipe (Python) 2011-12-17T20:03:26-08:00harish anandhttp://code.activestate.com/recipes/users/4180291/http://code.activestate.com/recipes/577987-yet-another-assignment-in-expression-recipe/ <p style="color: grey"> Python recipe 577987 by <a href="/recipes/users/4180291/">harish anand</a> (<a href="/recipes/tags/expression/">expression</a>, <a href="/recipes/tags/shortcuts/">shortcuts</a>). Revision 3. </p> <p>Python does not support assignment in if and while statements such as "if (x=func()):". This is an attempt to bring similar functionality to python by injecting bytecode to all functions and methods in a module. This recipe is inspired from recipes <a href="http://code.activestate.com/recipes/66061">66061</a>, <a href="http://code.activestate.com/recipes/202234-assignment-in-expression">202234</a> and <a href="http://code.activestate.com/recipes/277940-decorator-for-bindingconstants-at-compile-time">277940</a>.</p> Decorator for BindingConstants at compile time (Python) 2009-09-15T00:34:37-07:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/576904-decorator-for-bindingconstants-at-compile-time/ <p style="color: grey"> Python recipe 576904 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/optimisation/">optimisation</a>, <a href="/recipes/tags/optimization/">optimization</a>, <a href="/recipes/tags/programs/">programs</a>). </p> <p>Decorator for automatic code optimization. If a global is known at compile time, replace it with a constant. Fold tuples of constants into a single constant. Fold constant attribute lookups into a single constant.</p> <p>This is only an update of <a href="http://code.activestate.com/recipes/277940/">Recipe 277940</a>, making it compatible with Python 3. All credit must go to the original author, Raymond Hettinger.</p> Copying Generators (Python) 2007-10-09T07:38:06-07:00kay schluehrhttp://code.activestate.com/recipes/users/2398921/http://code.activestate.com/recipes/528949-copying-generators/ <p style="color: grey"> Python recipe 528949 by <a href="/recipes/users/2398921/">kay schluehr</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 5. </p> <p>This recipe presents copy_generator(...) which a pure Python function keeping a running generator object and returns a copy of the generator object being in the same state as the original generator object.</p> Decorator for BindingConstants at compile time (Python) 2010-11-16T08:36:38-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/277940-decorator-for-bindingconstants-at-compile-time/ <p style="color: grey"> Python recipe 277940 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 9. </p> <p>Decorator for automatic code optimization. If a global is known at compile time, replace it with a constant. Fold tuples of constants into a single constant. Fold constant attribute lookups into a single constant.</p>