Popular recipes by Paul McGuire http://code.activestate.com/recipes/users/1377254/2013-01-21T16:20:17-08:00ActiveState Code RecipesSplit a sequence or generator using a predicate (Python) 2013-01-21T16:20:17-08:00Paul McGuirehttp://code.activestate.com/recipes/users/1377254/http://code.activestate.com/recipes/578416-split-a-sequence-or-generator-using-a-predicate/ <p style="color: grey"> Python recipe 578416 by <a href="/recipes/users/1377254/">Paul McGuire</a> (<a href="/recipes/tags/partition/">partition</a>, <a href="/recipes/tags/sequence/">sequence</a>, <a href="/recipes/tags/splitting/">splitting</a>). Revision 3. </p> <p>Split a sequence or generator into two iterators, each iterating over the elements that either pass or fail a predicate function.</p> Low-impact script timing (Python) 2008-07-30T08:43:03-07:00Paul McGuirehttp://code.activestate.com/recipes/users/1377254/http://code.activestate.com/recipes/573436-low-impact-script-timing/ <p style="color: grey"> Python recipe 573436 by <a href="/recipes/users/1377254/">Paul McGuire</a> (<a href="/recipes/tags/debugging/">debugging</a>). Revision 3. </p> <p>As other timing recipes have mentioned, the timeit module could be easier to work with. Sometimes, I just want to bracket a particular script with start, stop, and duration timing info. The following module (which I named "timing.py") is about as non-intrusive as you can get - just import the module.</p> secondsToStr - h:mm:ss.sss formatting of floating point seconds (Python) 2007-04-20T07:28:47-07:00Paul McGuirehttp://code.activestate.com/recipes/users/1377254/http://code.activestate.com/recipes/511486-secondstostr-hmmsssss-formatting-of-floating-point/ <p style="color: grey"> Python recipe 511486 by <a href="/recipes/users/1377254/">Paul McGuire</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). </p> <p>Here is a small footprint routine to convert a number of floating point seconds (such as an elapsed time, found by subtracting an earlier return value from time.time() from a later value) to "0:00:00.000" format, instead of "time.strftime("%H:%M:%S",time.gmtime(t2-t1))+(".%03d" % (((t2-t1)-int(t2-t1))*1000))"</p> Word wrapping generator (Python) 2004-06-29T16:57:05-07:00Paul McGuirehttp://code.activestate.com/recipes/users/1377254/http://code.activestate.com/recipes/286129-word-wrapping-generator/ <p style="color: grey"> Python recipe 286129 by <a href="/recipes/users/1377254/">Paul McGuire</a> (<a href="/recipes/tags/text/">text</a>). Revision 2. </p> <p>A simple generator function to return an input string in fragments, each broken at spaces in the text.</p> How to define multiple initializers for a class, with different arguments (Python) 2008-07-30T08:36:56-07:00Paul McGuirehttp://code.activestate.com/recipes/users/1377254/http://code.activestate.com/recipes/223611-how-to-define-multiple-initializers-for-a-class-wi/ <p style="color: grey"> Python recipe 223611 by <a href="/recipes/users/1377254/">Paul McGuire</a> (<a href="/recipes/tags/extending/">extending</a>). Revision 6. </p> <p>Sometimes your class design warrants the definition of multiple construction methods for a class, such as rebuilding from a serialized form vs. normal internal construction with explicit parameters. This recipe gives an example of using class level methods to create such constructors.</p>