Most viewed recipes by Zoran Isailovski http://code.activestate.com/recipes/users/2400454/views/2008-10-26T06:35:11-07:00ActiveState Code RecipesDependency Injection The Python Way (Python) 2007-03-10T11:26:16-08:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/413268-dependency-injection-the-python-way/ <p style="color: grey"> Python recipe 413268 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/oop/">oop</a>). Revision 9. </p> <p>Sample Pythonic Inversion-of-Control Pseudo-Container.</p> Exception-based Switch-Case (Python) 2008-10-26T04:31:24-07:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/410695-exception-based-switch-case/ <p style="color: grey"> Python recipe 410695 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). Revision 11. </p> <p>Here is yet another way to emulate a switch-case statement, perhaps one you might not have thought of.</p> First Class Enums in Python (Python) 2005-05-09T16:53:44-07:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/413486-first-class-enums-in-python/ <p style="color: grey"> Python recipe 413486 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 7. </p> <p>True immutable symbolic enumeration with qualified value access.</p> Transposing a List of Lists with Different Lengths without Loosing Elements (Python) 2005-04-25T18:05:47-07:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/410687-transposing-a-list-of-lists-with-different-lengths/ <p style="color: grey"> Python recipe 410687 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 4. </p> <p>Sometimes you get a list of lists and want to swap rows and columns, i.e. transpose the list. Yet, what if the rows have different lengths? Here is some advice you might find useful in such situations.</p> C#-Style Events in Python (Python) 2008-10-26T06:35:11-07:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/410686-c-style-events-in-python/ <p style="color: grey"> Python recipe 410686 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/oop/">oop</a>). Revision 7. </p> <p>IMPROVED. The concept of events is heavily used in GUI libraries and is the foundation for most implementations of the MVC (Model, View, Controller) design pattern (the latter being my prime motivation for this recipe). Another prominent use of events is in communication protocol stacks, where lower protocol layers need to inform upper layers of incoming data and the like. Here is a handy class that encapsulates the core to event subscription and event firing and feels like a "natural" part of the language.</p> These Nasty Closures - Caveats for the Closure Enthusiast (Python) 2007-03-03T11:31:05-08:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/502271-these-nasty-closures-caveats-for-the-closure-enthu/ <p style="color: grey"> Python recipe 502271 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>Closures are powerful. Closures are beautiful. But: Closures are TRICKY!</p> <p>This is an anti-recipe, a caveat about some obscure pitfalls with closures - or the way they are implemented in python.</p> <p>And now for the caveats: Two no-no's...</p> <ol> <li><p>Don't create more then one instance of the same closure per normal function!</p></li> <li><p>Don't create more then one instance of the same closure per generation cycle in a generator function!</p></li> </ol> <p>Here is why...</p> Cache Handling Wrapper for Slow File Processing Functions (Python) 2005-05-05T18:16:00-07:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/412719-cache-handling-wrapper-for-slow-file-processing-fu/ <p style="color: grey"> Python recipe 412719 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 7. </p> <p>Some file processing tasks are quite time consuming, especially when COM is involved. Unnecessary repetitions are then unbearable. Here is a module that helps avoid them.</p> Memento Closure (Python) 2005-05-11T07:44:46-07:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/413838-memento-closure/ <p style="color: grey"> Python recipe 413838 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/oop/">oop</a>). Revision 3. </p> <p>The memento pattern is great for transaction-like processing. Having a handy implementation around might not be the worst thing.</p> Closures For Highly Readable Sequence Sorting Customization (Python) 2006-01-25T03:25:24-08:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/466335-closures-for-highly-readable-sequence-sorting-cust/ <p style="color: grey"> Python recipe 466335 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/oop/">oop</a>). Revision 6. </p> <p>Whenever I feel the impulse to write a class, I pause for a moment and think whether I can get away with a closure. This time I will be using closures to readably and flexibly customize the sorting of sequences (for Pythons 2.1 through 2.3).</p> Quick Test If Strings Are Identifiers (Python) 2005-05-08T10:42:59-07:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/413487-quick-test-if-strings-are-identifiers/ <p style="color: grey"> Python recipe 413487 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 3. </p> <p>Sometimes you need strings to be true identifiers, for ex. to represent symbolic names. Smalltalk offers the type 'Symbol' for this purpose. In python, you need to test this explicitly. Here is a quick way.</p> Generic vs. Specific Algorithms - Obtaining All Element Combinations from N Sets (Python) 2005-04-30T17:16:48-07:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/410685-generic-vs-specific-algorithms-obtaining-all-eleme/ <p style="color: grey"> Python recipe 410685 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 3. </p> <p>Two approaches to generate all combination of elements from a number of sets. Compares "classic" statically coded algorithms to a pythonic on-the-fly generation of specific algorithm code.</p> Dependency Injection The Python Way (Python) 2006-04-16T06:50:16-07:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/413267-dependency-injection-the-python-way/ <p style="color: grey"> Python recipe 413267 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/oop/">oop</a>). Revision 3. </p> <p>:( Somehow this recipe arived twice. Please go to <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413268" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413268</a> :o Dear editors, please remove this one</p> Reverting Columns of a 2D Iterable (Python) 2007-07-17T04:41:29-07:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/523050-reverting-columns-of-a-2d-iterable/ <p style="color: grey"> Python recipe 523050 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Every now and then I "discover" a cute one-liner data transformation idiom. Here is one to revert the order of columns in a 2-D iterable. It comes in handy to invert a dictionary (i.e. to swap keys and values).</p>