This is the third post in an article series about Python video lectures. The previous two posts covered learning basics of Python and learning Python design patterns.

This video lecture is given by Google's "Über Tech Lead" Alex Martelli. In this video he talks about the most important language changes in each of the Python versions 2.2, 2.3, 2.4 and 2.5.

I am actually using an older version of Python, version 2.3.4. This lecture gave me a good insight of what new features to expect when I upgrade to a newer version of Python.

Here it is:

Interesting information from lecture:

[01:30] There are many versions of Python - Jython, IronPython, pypy and CPython.

[03:02] Python 2.2 was a backwards-compatible revolution. It introduced new-style objects, descriptors, iterators and generators, nested scopes, a lot of new modules in standard library.

[04:12] New rule for introducing extra features: 2.N.* has not extra features with respect to 2.N.

[04:32] Python 2.2 highlights: metaclasses, closures, generators and iterators.

[05:35] Python 2.3 was a stable version of Python with no changes to the language.

[06:05] Python 2.3 had a lot of optimizations, tweaks and fixes, such as import-from-zip, Karatsuba multiplication algorithm, and new stdlib modules - bz2, csv, datetime, heapq, itertools, logging, optparse, textwrap, timeit, and many others.

[08:50] Python 2.3 highlights: zip imports, sum builtin, enumerate builtin, extended slices, universal newlines.

[09:50] Python 2.4 added two new language features - generator expressions and decorators. New builtins were added - sorted, reversed and set, frozenset. New modules - collections, cookielib, decimal, subprocess.

[13:00] Example of generator expressions and decorators

[13:37] Example of sorted() and reversed() builtins.

[16:40] Python 2.5 was also evolution of language. It came with full support for RAII (with statement), introduced two new builtins - any and all, unified exceptions and added a ternary operator. New modules - ctypes, xml.etree, functools, hashlib, sqlite3, wsgiref, and others.

[18:40] Python 2.5 optimizations.

[23:25] RAII - Resource Allocation is Initialization.

[25:30] Examples of RAII.

[31:05] Python RAII is better than C++'s. Python's RAII can distinguish exception exits from normal ones.

[33:29] Example of writing your own context manager.

[36:30] Example of writing a RAII ready type with contextlib.

[38:05] Following Python's Zen, "Flat is better than nested", use contextlib.nested for multiple resources.

[40:40] Generator enhancements - yield can be inside a try clause, yield is now an expression (almost co-routines!).

[44:50] Python 2.5 absolute/relative imports.

[47:00] Joke - "If you exceed 200 dots when using relative imports, you have a serious psychological problem".

[47:45] Python 2.5 try/except/else/finally.

[48:55] Python 2.5 if/else ternary operator.

[49:35] Python 2.5 exceptions are new style.

[51:15] Python 2.5 any and all builtins.

[54:00] collections.defaultdict subclasses dict and overrides __missing__.

[56:55] ctypes is probably the most dangerous addition to Python. One mistake and you crash.

[01:01:30] hashlib replaces md5 and sha modules, and adds sha-(224|256|384|512). Uses OpenSSL as accelerator (if available).

[01:02:29] Lecture got cut here but the presentation still had two slides on sqlite3 and wsgiref!

Here is the timeline of Python versions. I hope Alex doesn't mind that I took it from his presentation. :)

If you don't know what new-style objects are about, see these two tutorials:

Have fun writing better code in Python!