[triangle-zpug] Alex Martelli on Python 2.5
cbc at unc.edu
Tue Aug 22 17:31:36 CEST 2006
If you are reading this on the PyCamp mailing list, please subscribe to
the TriZPUG mailing list. And don't forget the TriZPUG meeting tonight.
Alex Martelli is the fine author of Python in a Nutshell. I you came to
PyCamp and want a more reference-manual-like Python book, get Alex's
book. It takes ten times as long to read as Dive Into Python. But it
leaves no stone unturned.
Python 2.5 is now in release candidate mode. It may even get released
this month. And Alex has made a nice Python 2.5 presentation for his
user group in San Francisco:
If you came to PyCamp, there are some things to note about Python 2.5
from Alex's presentation:
1) New "RAII" (Resource Allocation Is Initialization) programming model
implemented with the new "with" statement. This helps you be a good
resource citizen. And Python is the first to make this part of the base
language. It treats system resources much like memory is treated by
garbage collection. When you are finished with a system resource, its
close method automatically gets called.
2) try/except/else/finally are now unified. You can have a "finally"
with "except" and "else." It actually condenses the nested
try/except/else within a try/finally which you saw at PyCamp. The
unified version is, or course, more readable because flat is better than
3) There's a new "ternary" if/else operator. You no longer have to do
the "and-or" trick to mimic a ternary operator. (Although you still need
to understand the "and-or" trick in order to read most pre-existing code).
4) If you use scientific packages which make use of C and Fortran
libraries, the ctypes module is now "built-in." You can now crash Python
to your heart's delight by using poorly written C and Fortran modules. :)
5) A new built-in package, xml.etree, is a "highly Pythonic in-memory
representation of XML document as tree, much slimmer and faster than
xml.dom." It's highly Pythonic because "each XML element is a bit like a
list of its children merged with a dict of its attrs." That is, you get
back things that look and act like Python sequences and mappings instead
of getting back complex objects where you have to call methods on the
objects in order to get the sequences and mappings you really want. You
can also make these sequences and mappings act like you want with
6) sqlite is now a built-in module. sqlite helps you prototype SQL
applications before having to set up and connect to big SQL servers like
Oracle or PostGreSQL. Some applications like Trac actually use SQLite
for production. (Trac is also written in Python.) I've had no problem
hacking the SQLite databases in my Trac instances using Python when I
wanted to automate reorganizing the wiki page hierarchy in Trac.
7) Make note of how many new Python 2.5 features make use of wrapper
I sure hope this means Alex is going to update Python in a Nutshell.
Also, Python 2.3.5 is good to use for a long, long time. It is very
stable, well understood, and well liked.
office: 17-6 Venable Hall phone: (919) 962-4323
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599
More information about the triangle-zpug