Saturday, March 18, 2006

Sneak Preview Of Python 2.5

Here's my sneak peak at the upcoming Python 2.5. There are no earth-shattering changes, rather a gentle increase in functionality, extending syntax to reduce code verbosity.

First, you may be pleased to know that the standard library will be enhanced to include "setuptools" and Fredrik Lundh's ElementTree. The new "hashlib" module will provide a superset of "md5" and "sha".

The new absolute import syntax will make it clear whether the module being imported is within the current package.

The "with" statement allows for constructs that have guaranteed exit behaviour. It took me a while to understand this, but basically it's a way of getting around writing lots of try/finally blocks.

A conditional expression is being added in the form "X if C else Y". Python will finally have a ternary! But rather than operator form, this looks like list comprehensions.

Generators will be enhanced to make them usable as coroutines.

There will be a new formulation to allow try-except-finally, saving some further code verbosity.

The exception hierarchy will change so that KeyboardInterrupt, SystemExit and Exception inherit from BaseException. This means that Exception includes only exceptions that signify errors.

Currying is to be provided by a function in the new "functional" module.

Arbitrary objects can be used for slicing, where currently integers are required.

There is a new standard mechanism for adding metadata to Python packages. The Distutils "sdist" command will write metadata fields to a file named PKG-INFO.

For excrutiating details, have a look at PEP 356. There's also a tentative What's New page available.

Expect Python 2.5 to be available in release form by October 2006.


No comments:

Post a Comment