Diving Into Python

Update: speaking of Python, read Guido van Rossum's Python 3000 update.

Let's say you, like Tom Kralidis, are getting into Python because it's the best environment for combining MapServer and GDAL/OGR. Not only in scripts, but at the interpreter prompt. You'd like to not only learn to do the same old stuff in a new language, but also to learn some new tricks and increase your programming Fu. You're in luck, because Python is a great environment for knowledge acquisition.

Tom writes:

So here's what I typically start off with when doing development:

  • HTTP / URLs / Forms: for Perl, I use CGI; for PHP, I use the native, built in functions

My recommendation is to leave CGI at the door. If you want to learn about Python web programming, start with WSGI. Joe Gregorio calls it the "Java servlet API for Python", but to me it also feels a lot like good old CGI. There is a reference implementation in the Python 2.5 standard library, and wsgiref is also easy to acquire for Python 2.4. For web page templating, I recommend Genshi.

  • XML Processing: for Perl, I use XML::Simple; for PHP, I use SimpleXMLElement

Take the opportunity to learn how to use XPath. For example, see how WxS metadata is parsed in OWSLib using element.find and element.findall.

  • Database: for Perl, I use DBI; for PHP, I use the compiled in mysql support, for example

You already know how to execute SQL in a scripting context, so why not try out one of the interesting object-relational APIs for Python such as SQLAlchemy.

Joe Gregorio's Robaccia tutorial covers everything you need to know about modern Python web programming. Read it, code it, run it. Then try a community supported framework like Django. Then think about using these new tools in some geo applications. My toy not-a-WFS Hammock has some good examples, and MetaCarta's TileCache also works with any WSGI server.

The name of this post is a reference to Mark Pilgrim's Dive Into Python, a great resource. Just don't follow Pilgrim into xml.dom or unittest, use ElementTree or lxml, and doctest instead.

At any rate, do experiment with Python community packages. The SWIG or SIP-generated stuff that comes out of our GIS world tends to obscure the goodness of Python.

Comments

Re: Diving Into Python

Author: Allan

I second the recommendation of Dive Into Python.