Popular recipes by Michele Simionato http://code.activestate.com/recipes/users/1122360/2014-09-29T07:15:33-07:00ActiveState Code RecipesSemi-automatic resource management with AutoClose (Python) 2009-11-18T21:37:55-08:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/523007-semi-automatic-resource-management-with-autoclose/ <p style="color: grey"> Python recipe 523007 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/oop/">oop</a>). Revision 4. </p> <p>This recipe provides a semi-automatic mechanism to close resources.</p> [Twisted] From blocking functions to deferred functions (Python) 2005-08-19T09:05:30-07:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/439358-twisted-from-blocking-functions-to-deferred-functi/ <p style="color: grey"> Python recipe 439358 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/threads/">threads</a>). Revision 2. </p> <p>Twisted FAQs clearly state that "deferreds do not magically convert blocking code into non-blocking code". So, how do you magically convert blocking code into non-blocking code?</p> <p>This recipe is the solution!</p> Caching object creation (Python) 2005-05-09T23:57:45-07:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/413717-caching-object-creation/ <p style="color: grey"> Python recipe 413717 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/oop/">oop</a>). </p> <p>This cookbook contains many recipes to memoize functions, however a recipe to memoize classes was missing. Using this recipe you can cache object creation, i.e. __new__ and __init__ methods are called only when needed. For a good use case, see the discussion around <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413609" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413609</a></p> A simple and useful doctester for your documentation (Python) 2005-04-16T09:15:09-07:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/410052-a-simple-and-useful-doctester-for-your-documentati/ <p style="color: grey"> Python recipe 410052 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 3. </p> <p>The doctester extracts code from stdin and tests it using the doctest module in the standard library. It can be invoked from the command line, but it is best called from you editor of choice. I just give an example for Emacs.</p> How to serve files from a directory (and/or testing CGI scripts) (Python) 2005-02-02T22:34:33-08:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/365606-how-to-serve-files-from-a-directory-andor-testing-/ <p style="color: grey"> Python recipe 365606 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/web/">web</a>). </p> <p>The standard library modules SimpleHTTPServer and CGIHTTPServer are extremely useful, but the documentation hides their virtues. I hope to improve the situation with this recipe.</p> SOLVING THE METACLASS CONFLICT (Python) 2014-09-29T07:15:33-07:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/204197-solving-the-metaclass-conflict/ <p style="color: grey"> Python recipe 204197 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/oop/">oop</a>). Revision 5. </p> <p>Any serious user of metaclasses has been bitten at least once by the infamous metaclass/metatype conflict. Here I give a general recipe to solve the problem, as well as some theory and some examples.</p> Easy string interpolation in Python 2.4 (Python) 2004-11-12T02:46:30-08:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/335308-easy-string-interpolation-in-python-24/ <p style="color: grey"> Python recipe 335308 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/text/">text</a>). </p> <p>Regular string interpolation in Python requires the user to pass an explicit keyword dictionary. This recipe adds a little bif of magic, so that if a name is not found in the passed dictionary, it is looked up in the locals and globals dictionaries. It is also possible not to pass any explicit dictionary, then the names is searched in the locals and globals dictionaries only.</p> Parsing the command line (Python) 2004-04-18T08:15:21-07:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/278844-parsing-the-command-line/ <p style="color: grey"> Python recipe 278844 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 2. </p> <p>The module optparse was a great addition to Python 2.3, since it is much more powerful and easier to use than getopt. Using optparse, writing command-line tools is a breeze. However, the power of optparse comes together with a certain verbosity. This recipe allows to use optparse with a minimum of boilerplate, trading flexibility for easy of use. Still, it covers 95% of my common needs, so I think it may be useful to others.</p> How to freeze Python classes (Python) 2003-11-20T23:08:39-08:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/252158-how-to-freeze-python-classes/ <p style="color: grey"> Python recipe 252158 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/oop/">oop</a>). </p> <p>This recipe is here for a couple of reasons: 1) discourage a common misuse of __slots__; 2) show how to restrict Python dynamism.</p> A nicer syntax for super(cls,self) (Python) 2004-05-19T10:59:30-07:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/284528-a-nicer-syntax-for-superclsself/ <p style="color: grey"> Python recipe 284528 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). Revision 2. </p> <p>Makes cooperative calls looks nicer: super.method instead of super(cls,self).method .</p> Drawing inheritance diagrams with "Dot" (Python) 2003-08-03T07:54:55-07:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/213898-drawing-inheritance-diagrams-with-dot/ <p style="color: grey"> Python recipe 213898 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/oop/">oop</a>). </p> <p>Dot is a very nice graph description language developed at MIT and available for free at <a href="http://www.graphviz.org/" rel="nofollow">http://www.graphviz.org/</a> . Combined with Python, it makes an ideal tool to automatically generate diagrams. I will describe here a short recipe which produces beautiful inheritance diagrams for Python classes (and metaclasses too). In particular the recipe allows to display the MRO (Method Resolution Order) for complicate inheritance hierarchies.</p> Checking multiple endings (Python) 2003-07-30T12:37:30-07:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/212959-checking-multiple-endings/ <p style="color: grey"> Python recipe 212959 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). Revision 3. </p> <p>A short idiom for s.endswith(ending1) or s.endswith(ending2) or s.endswith(ending3) or ... Shows the goodies of the Python 2.3 itertools module and summarizes a discussion on c.l.py (thread "a better str.endswith", July 2003)</p>