I l@ve RuBoard Previous Section Next Section

A.2 Major Changes in 1.6

This section lists changes introduced by Python release 1.6; by proxy, most are part of release 2.0 as well.

A.2.1 Incompatibilities

The append method for lists can no longer be invoked with more than one argument. This used to append a single tuple made out of all arguments, but was undocumented. To append a tuple, write l.append((a, b, c)).

The connect, connect_ex, and bind methods for sockets require exactly one argument. Previously, you could call s.connect(host, port), but this was not by design; you must now write s.connect((host, port)).

The str and repr functions are now different more often. For long integers, str no longer appends an "L"; str(1L) is "1", which used to be "1L", and repr(1L) still returns "1L". For floats, repr now gives 17 digits of precision to ensure that no precision is lost (on all current hardware).

Some library functions and tools have been moved to the deprecated category, including some widely used tools such as find. The string module is now simply a frontend to the new string methods, but given that this module is used by almost every Python module written to date, it is very unlikely to go away.

A.2.2 Core Language Changes

The following sections describe changes made to the Python language itself.

A.2.2.1 Unicode strings

Python now supports Unicode (i.e., 16-bit wide character) strings. Release 1.6 added a new fundamental datatype (the Unicode string), a new built-in function unicode, and numerous C APIs to deal with Unicode and encodings. Unicode string constants are prefixed with the letter "u", much like raw strings (e.g., u"..."). See the file Misc/unicode.txt in your Python distribution for details, or visit web site http://starship.python.net/crew/lemburg/unicode-proposal.txt.

A.2.2.2 String methods

Many of the functions in the string module are now available as methods of string objects. For instance, you can now say str.lower( ) instead of importing the string module and saying string.lower(str). The equivalent of string.join(sequence,delimiter) is delimiter.join(sequence). (That is, you use " ".join(sequence) to mimic string.join(sequence)).

A.2.2.3 New (internal) regular expression engine

The new regular expression engine, SRE, is fully backward-compatible with the old engine, and is invoked using the same interface (the re module). That is, the re module's interface remains the way to write matches, and is unchanged; it is simply implemented to use SRE. You can explicitly invoke the old engine by importing pre, or the SRE engine by importing sre. SRE is faster than pre, and supports Unicode (which was the main reason to develop yet another underlying regular expression engine).

A.2.2.4 apply-like function calls syntax

Special function call syntax can be used instead of the apply function: f(*args, **kwds) is equivalent to apply(f, args, kwds). You can also use variations like f(a1, a2, *args, **kwds), and can leave one or the other out (e.g., f(*args), f(**kwds)).

A.2.2.5 String to number conversion bases

The built-ins int and long take an optional second argument to indicate the conversion base, but only if the first argument is a string. This makes string.atoi and string.atol obsolete. (string.atof already was.)

A.2.2.6 Better errors for local name oddities

When a local variable is known to the compiler but undefined when used, a new exception UnboundLocalError is raised. This is a class derived from NameError, so code that catches NameError should still work. The purpose is to provide better diagnostics in the following example:

x = 1
def f(  ):
    print x
    x = x+1

This used to raise a confusing NameError on the print statement.

A.2.2.7 Membership operator overloading

You can now override the in operator by defining a __contains_ _ method. Note that it has its arguments backward: x in a runs a.__contains__(x) (that's why the name isn't __in__).

A.2.3 Selected Library Module Changes

This section lists some of the changes made to the Python standard library.


New; tools for distributing Python modules.


New; read and write zip archives (module gzip does gzip files).


New; access to the Unicode 3.0 database.


New; Windows registry access (one without the _ is in progress).

socket , httplib, urllib

Expanded to include optional OpenSSL secure socket support (on Unix only).


Support for Tk versions 8.0 through 8.3.


This module no longer uses the built-in C strop module, but takes advantage of the new string methods to provide transparent support for both Unicode and ordinary strings.

A.2.4 Selected Tools Changes

This section lists some of the changes made to Python tools.


Completely overhauled. See the IDLE home page at http://www.python.org for more information.


Python equivalent of xgettext message text extraction tool used for internationalizing applications written in Python.

    I l@ve RuBoard Previous Section Next Section