n September 19th, 2006, Python enthusiasts were rewarded with a new version. Python 2.5 continues the honorable tradition of improving and enhancing the language carefully while extending its impressive standard library.
This article is the first part in a three-part series about Python 2.5. I'll begin with a broad-stroke summary of the changes in Python 2.5 and set the stage for a detailed exploration. The rest of this article discusses the major language enhancements in Python 2.5. Part 2 of this series will present the major new and improved modules in Python 2.5, and Part 3 will discuss a whole bag of smaller improvements and changes that are relevant to specific subsets of the Python community.
Python 2.5 at a Glance
Python 2.5 introduced some significant language changes. The venerable try-except and try-finally blocks have been unified. The functional programming style got a boost via partial functions and other additions to the functools module. The new 'with' statement enables safer resource management and brings along the contextlib module. Generators are more interactive and it is possible to insert values into existing generators. Conditional expressions might seem a little weird at first, but there is a good reason for their syntax. I'll cover these features in the remainder of this article.
In the next article I'll cover the ctypes, sqlite3, and xml.etree.ElementTree packages that are both super-cool and super-important for hassle-free deployments of Python systems without distributing a slew of external modules and libraries. ctypes allows calling C code in dynamic libraries directly from Python code. sqlite3 is a Python front-end to the excellent sqlite embedded database, and ElementTree is a highly pythonic and efficient XML parser.
Major Language Changes
Python 2.5 brings quite a few language enhancements while staying backward compatible with Python 2.4.x. These include:
- Exception handling syntax
- Functional programming improvements
- New resource management facilities
- Generator enhancements
- Conditional expressions