blob: aa64b86dcf7056d7c1af6d561d82f812957edc0a [file] [log] [blame]
Fred Drakeed0fa3d2003-07-30 19:14:09 +00001\documentclass{howto}
2\usepackage{distutils}
3% $Id$
4
5\title{What's New in Python 2.4}
6\release{0.0}
7\author{A.M.\ Kuchling}
8\authoraddress{\email{amk@amk.ca}}
9
10\begin{document}
11\maketitle
12\tableofcontents
13
14This article explains the new features in Python 2.4. No release date
15for Python 2.4 has been set; expect that this will happen in 2004.
16
17While Python 2.3 was primarily a library development release, Python
182.4 may extend the core language and interpreter in
19as-yet-undetermined ways.
20
21This article doesn't attempt to provide a complete specification of
22the new features, but instead provides a convenient overview. For
23full details, you should refer to the documentation for Python 2.4.
24% add hyperlink when the documentation becomes available online.
25If you want to understand the complete implementation and design
26rationale, refer to the PEP for a particular new feature.
27
28
29%======================================================================
30
31% Large, PEP-level features and changes should be described here.
32
33
34%======================================================================
35\section{Other Language Changes}
36
37Here are all of the changes that Python 2.4 makes to the core Python
38language.
39
40\begin{itemize}
Andrew M. Kuchling2fb4d512003-10-21 12:31:16 +000041\item The \method{sort()} method of lists gained three keyword
42arguments, \var{cmp}, \var{key}, and \var{reverse}. These arguments
43make some common usages of \method{sort()} simpler. All are optional.
44
45\var{cmp} is the same as the previous single argument to
46\method{sort()}; if provided, the value should be a comparison
47function that takes two arguments and returns -1, 0, or +1 depending
48on how the arguments compare.
49
50\var{key} should be a single-argument function that takes a list
51element and returns a comparison key for the element. The list is
52then sorted using the comparison keys. The following example sorts a list
53case-insensitively:
54
55\begin{verbatim}
56>>> L = ['A', 'b', 'c', 'D']
57>>> L.sort() # Case-sensitive sort
58>>> L
59['A', 'D', 'b', 'c']
60>>> L.sort(key=lambda x: x.lower())
61>>> L
62['A', 'b', 'c', 'D']
63>>> L.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
64>>> L
65['A', 'b', 'c', 'D']
66\end{verbatim}
67
68The last example, which uses the \var{cmp} parameter, is the old way
69to perform a case-insensitive sort. It works, but is slower than
70using a \var{key} parameter. Using \var{key} results in calling the
71\method{lower()} method once for each element in the list while using
72\var{cmp} will call the method twice for each comparison.
73
74The \var{reverse} parameter should have a Boolean value. If the value is
75\constant{True}, the list will be sorted into reverse order. Instead
76of \code{L.sort() ; L.reverse()}, you can now write
77\code{L.sort(reverse=True)}.
Fred Drakeed0fa3d2003-07-30 19:14:09 +000078
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +000079\item The \function{zip()} built-in function and \function{itertools.izip()} now return an empty list
80 instead of raising a \exception{TypeError} exception if called
81 with no arguments.
82
Fred Drakeed0fa3d2003-07-30 19:14:09 +000083\end{itemize}
84
85
86%======================================================================
87\subsection{Optimizations}
88
89\begin{itemize}
90
91\item Optimizations should be described here.
92
93\end{itemize}
94
95The net result of the 2.4 optimizations is that Python 2.4 runs the
96pystone benchmark around XX\% faster than Python 2.3 and YY\% faster
97than Python 2.2.
98
99
100%======================================================================
101\section{New, Improved, and Deprecated Modules}
102
103As usual, Python's standard library received a number of enhancements and
104bug fixes. Here's a partial list of the most notable changes, sorted
105alphabetically by module name. Consult the
106\file{Misc/NEWS} file in the source tree for a more
107complete list of changes, or look through the CVS logs for all the
108details.
109
110\begin{itemize}
111
Andrew M. Kuchling69f31eb2003-08-13 23:11:04 +0000112\item The \module{curses} modules now supports the ncurses extension
113 \function{use_default_colors()}. On platforms where the terminal
114 supports transparency, this makes it possible to use a transparent background.
115 (Contributed by J\"org Lehmann.)
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000116
117\item The \module{random} module has a new method called \method{getrandbits(N)}
118 which returns an N-bit long integer.
119
120\item The regular expression language accepted by the \module{re} module
121 was extended with simple conditional expressions, written as
122 \code{(?(\var{group})\var{A}|\var{B})}. \var{group} is either a
123 numeric group ID or a group name defined with \code{(?P<group>...)}
124 earlier in the expression. If the specified group matched, the
125 regular expression pattern \var{A} will be tested against the string; if
126 the group didn't match, the pattern \var{B} will be used instead.
Andrew M. Kuchling69f31eb2003-08-13 23:11:04 +0000127
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000128\end{itemize}
129
130
131%======================================================================
132% whole new modules get described in \subsections here
133
134
135% ======================================================================
136\section{Build and C API Changes}
137
138Changes to Python's build process and to the C API include:
139
140\begin{itemize}
141
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000142 \item Three new convenience macros were added for common return
143 values from extension functions: \csimplemacro{Py_RETURN_NONE},
144 \csimplemacro{Py_RETURN_TRUE}, and \csimplemacro{Py_RETURN_FALSE}.
145
146 \item A new function, \cfunction{PyTuple_Pack(N, obj1, obj2, ...,
147 objN)}, constructs tuples from a variable length argument list of
148 Python objects.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000149
150\end{itemize}
151
152
153%======================================================================
154\subsection{Port-Specific Changes}
155
156Platform-specific changes go here.
157
158
159%======================================================================
160\section{Other Changes and Fixes \label{section-other}}
161
162As usual, there were a bunch of other improvements and bugfixes
163scattered throughout the source tree. A search through the CVS change
164logs finds there were XXX patches applied and YYY bugs fixed between
165Python 2.3 and 2.4. Both figures are likely to be underestimates.
166
167Some of the more notable changes are:
168
169\begin{itemize}
170
171\item Details go here.
172
173\end{itemize}
174
175
176%======================================================================
177\section{Porting to Python 2.4}
178
179This section lists previously described changes that may require
180changes to your code:
181
182\begin{itemize}
183
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000184\item The \function{zip()} built-in function and \function{itertools.izip()} now return an empty list
185 instead of raising a \exception{TypeError} exception if called
186 with no arguments.
187
188\item \function{dircache.listdir()} now passes exceptions to the caller
189 instead of returning empty lists.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000190
191\end{itemize}
192
193
194%======================================================================
195\section{Acknowledgements \label{acks}}
196
197The author would like to thank the following people for offering
198suggestions, corrections and assistance with various drafts of this
199article: .
200
201\end{document}