Popular recipes by Chris McDonough http://code.activestate.com/recipes/users/98018/popular/2001-12-27T08:59:27-08:00ActiveState Code RecipesUsing time "slices" to categorize events by period (Python) 2001-12-27T08:59:27-08:00Chris McDonoughhttp://code.activestate.com/recipes/users/98018/http://code.activestate.com/recipes/104734-using-time-slices-to-categorize-events-by-period/ <p style="color: grey"> Python recipe 104734 by <a href="/recipes/users/98018/">Chris McDonough</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Break all of time up into "slices" in order to categorize events.</p> Implementing a circular data structure using lists (Python) 2001-03-13T18:16:59-08:00Chris McDonoughhttp://code.activestate.com/recipes/users/98018/http://code.activestate.com/recipes/52246-implementing-a-circular-data-structure-using-lists/ <p style="color: grey"> Python recipe 52246 by <a href="/recipes/users/98018/">Chris McDonough</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>In some applications, it's advantageous to be able to define a circular data structure (a structure in which the last element is a pointer to the first). Python lists make it easy to make such a beast. A list is an ordered sequence of elements, so implementing a "ring" as a Python list is easy. "Turning" the ring consists of removing the last element from the list and placing it in the list's beginning slot. We can encapsulate this behavior in a class, which is shown below as the "Ring" class.</p> Use simple command-line options to effect program runtime. (Python) 2001-03-03T10:37:03-08:00Chris McDonoughhttp://code.activestate.com/recipes/users/98018/http://code.activestate.com/recipes/52206-use-simple-command-line-options-to-effect-program-/ <p style="color: grey"> Python recipe 52206 by <a href="/recipes/users/98018/">Chris McDonough</a> . </p> <p>Using sys.argv and globals(), you can build scripts which can modify their behavior at runtime based on arguments passed on the command line. This script, 'test_test.py' is built to be run from the command line. It allows you to invoke the script without any command-line arguments, in which case, the main() function is run. However, if the script is invoked via "python test_test.py debug", the debug function is run instead. This script uses Stephen Purcell's 'unittest' module from his PyUnit unit testing framework.</p> Replace if and while statement expressions with '0'. (Python) 2001-03-04T12:31:09-08:00Chris McDonoughhttp://code.activestate.com/recipes/users/98018/http://code.activestate.com/recipes/52208-replace-if-and-while-statement-expressions-with-0/ <p style="color: grey"> Python recipe 52208 by <a href="/recipes/users/98018/">Chris McDonough</a> . </p> <p>While debugging, if you don't want a section of code to be executed temporarily, replace the expression after an 'if' or 'while' with '0' and comment out the old expression, leaving it in place.</p>