Examining Python 2.3: New Additions

Python 2.3 is around the corner. What will this new release bring? Is it mere nerd-fodder, or is there more to the changes Guido van Rossum and his team are implementing? Boudewijn Rempt examines the most important additions to the language and libraries, and shows how to use them with examples.

Like this article? We recommend

It won't be long now before the next version of the
Python programming language
becomes available for general use. I've been messing around with the first
alpha for some time now, and I really like what's in therefrom a
techie's perspective, that is.

But techies always like new toys, even if those toys aren't too useful
in the dreary daily grind. Whether there will be compelling, practical reasons
to upgrade to the new version of Python is one of the questions I set out to
answer when I started investigating the new Python 2.3a.

Python has been a very stable language for quite a long time. Version 1.5.2
was stable and relatively bug-free, and it offered the most important constructs
needed to code most algorithms. It also came with batteries included: lots and
lots of stable libraries.

With Python 2.0, the core language started acquiring new features at a rate
of knots. Most developers won't be using the new features all that much:
Generators are extremely cool, but at the same time, are not a tool that
people grope for instinctively. And there are many more new features. It will
take a long time for developers to catch up.

Python now includes iterators, generators, list comprehensions, nested
scopes, type unificationand complete Unicode compatibility. The older
functional programming style constructs, such as map, filter, reduce, and lambda
are deprecated, even if it's unlikely that they will disappear.

Python 2.3

With Python 2.3, the rate of feature accretion seems to have slowed a bit.
That's a good thing, in my opinion, because one of the main advantages of
Python is that it makes it possible for most developers to keep the whole
language in their head, even if they are subject specialists for whom
programming is a tool to help them with their work instead of a full-time job or
a hobby.

That said, there's enough to get excited about: Some built-in functions
have been upgraded, and a few have been added. Most of the work has been done on
the batteries, though. Most interesting is the addition of a real logging
library. Logging through print statements doesn't cut it. We now have sets,
a bz2 compression lib, SSL added to IMAP, a far superior random generator, a
text wrapper, the ability to write source in encodings other than ASCII, a new
command-line option parser, and, finally, zipimport, which can be used to
package your Python modules in a ZIP file and import from that. Rather like
Java's JAR, it's a very welcome addition.

Improvements that were are not in the Alpha that I tested but that are being
discussed on the python-dev mailing list are better pickling of new-style
classes, upgrading of parts of the standard installation, and a module to handle
UNIX-style TAR files, in all useful compression formats.

A very serious problem is that Python's sandbox rexec and bastion
modules have become complete unsafe and, thus, unusable. This means that Python
can no longer be used to execute mobile code, for instance. A fix does not seem
to be forthcoming. There is some hope: This situation is very seriousit
affects the Python interpreter embedded in PostgreSQL, for instanceand
people are working on it.

I think that the absolute highlights of Python 2.3 are the new Set datatype,
the bool type and the logging package, and a number of smaller enhancements to
existing classes. I'll discuss each of these features briefly.