Popular recipes by Will Ware http://code.activestate.com/recipes/users/98156/2001-08-23T18:25:12-07:00ActiveState Code RecipesEnums for Python (Python) 2001-08-23T14:57:17-07:00Will Warehttp://code.activestate.com/recipes/users/98156/http://code.activestate.com/recipes/67107-enums-for-python/ <p style="color: grey"> Python recipe 67107 by <a href="/recipes/users/98156/">Will Ware</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>I once tried to give Python something like C's enums, as described here: <a href="http://groups.google.com/groups?selm=G6qzLy.6Fo%2540world.std.com" rel="nofollow">http://groups.google.com/groups?selm=G6qzLy.6Fo%40world.std.com</a> That approach tried to assign to a dictionary returned by the locals() function, intending that such assignments would become class attributes. The Tim-bot explained to me the errors of my ways. The quest for the perfect Python enum goes on.</p> dependency generator for makefiles (Python) 2001-08-20T18:10:33-07:00Will Warehttp://code.activestate.com/recipes/users/98156/http://code.activestate.com/recipes/66541-dependency-generator-for-makefiles/ <p style="color: grey"> Python recipe 66541 by <a href="/recipes/users/98156/">Will Ware</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>This script scans .c files for "#include" statements and creates a list of dependencies, suitable for inclusion in a makefile. Name this script "mkdep" and then type "mkdep *.c"; dependencies will come out standard output.</p> help in debugging memory problems (Python) 2001-08-23T18:25:12-07:00Will Warehttp://code.activestate.com/recipes/users/98156/http://code.activestate.com/recipes/67112-help-in-debugging-memory-problems/ <p style="color: grey"> Python recipe 67112 by <a href="/recipes/users/98156/">Will Ware</a> (<a href="/recipes/tags/extending/">extending</a>). </p> <p>When developing C extensions and running into memory problems, I find the typical problem is mismanagement of reference counts, particularly abuses of Py_INCREF and Py_DECREF, as well as forgetfulness of the refcount effects of functions like Py_BuildValue, PyArg_ParseTuple, PyTuple/List_SetItem/GetItem, etc. The 1.5.2 source codebase offers some help with this (search for Py_TRACE_REFS) but I found it useful to add this function in Objects/object.c, just before _Py_PrintReferences.</p> <p>Unlike _Py_PrintReferences, this function will print only the total of all the refcounts in the system, so it can be used safely in loops that will repeat millions of times, where_Py_PrintReferences would print out way too much stuff to be useful. This can help you to identify errantly wandering Py_INCREFs and Py_DECREFs.</p> Latitude/longitude/map web-fetcher (Python) 2001-08-20T18:11:28-07:00Will Warehttp://code.activestate.com/recipes/users/98156/http://code.activestate.com/recipes/52548-latitudelongitudemap-web-fetcher/ <p style="color: grey"> Python recipe 52548 by <a href="/recipes/users/98156/">Will Ware</a> (<a href="/recipes/tags/web/">web</a>). Revision 2. </p> <p>Given a list of cities, this recipe fetches their latitudes and longitudes from one website (a database used for astrology, of all things) and uses them to build a URL for another website which creates a map highlighting the cities against the outlines of continents. Maybe some day it will be clever enough to load the latitudes and longitudes as waypoints into your GPS receiver.</p>