blob: efa1ef26f72270d7611696c532965810c7924796 [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
79\end{itemize}
80
81
82%======================================================================
83\subsection{Optimizations}
84
85\begin{itemize}
86
87\item Optimizations should be described here.
88
89\end{itemize}
90
91The net result of the 2.4 optimizations is that Python 2.4 runs the
92pystone benchmark around XX\% faster than Python 2.3 and YY\% faster
93than Python 2.2.
94
95
96%======================================================================
97\section{New, Improved, and Deprecated Modules}
98
99As usual, Python's standard library received a number of enhancements and
100bug fixes. Here's a partial list of the most notable changes, sorted
101alphabetically by module name. Consult the
102\file{Misc/NEWS} file in the source tree for a more
103complete list of changes, or look through the CVS logs for all the
104details.
105
106\begin{itemize}
107
Andrew M. Kuchling69f31eb2003-08-13 23:11:04 +0000108\item The \module{curses} modules now supports the ncurses extension
109 \function{use_default_colors()}. On platforms where the terminal
110 supports transparency, this makes it possible to use a transparent background.
111 (Contributed by J\"org Lehmann.)
112
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000113\end{itemize}
114
115
116%======================================================================
117% whole new modules get described in \subsections here
118
119
120% ======================================================================
121\section{Build and C API Changes}
122
123Changes to Python's build process and to the C API include:
124
125\begin{itemize}
126
127\item Detailed changes are listed here.
128
129\end{itemize}
130
131
132%======================================================================
133\subsection{Port-Specific Changes}
134
135Platform-specific changes go here.
136
137
138%======================================================================
139\section{Other Changes and Fixes \label{section-other}}
140
141As usual, there were a bunch of other improvements and bugfixes
142scattered throughout the source tree. A search through the CVS change
143logs finds there were XXX patches applied and YYY bugs fixed between
144Python 2.3 and 2.4. Both figures are likely to be underestimates.
145
146Some of the more notable changes are:
147
148\begin{itemize}
149
150\item Details go here.
151
152\end{itemize}
153
154
155%======================================================================
156\section{Porting to Python 2.4}
157
158This section lists previously described changes that may require
159changes to your code:
160
161\begin{itemize}
162
Martin v. Löwisc6bb6c02003-09-20 15:52:21 +0000163\item dircache.listdir now passes exceptions to the caller,
164instead of returning empty lists.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000165
166\end{itemize}
167
168
169%======================================================================
170\section{Acknowledgements \label{acks}}
171
172The author would like to thank the following people for offering
173suggestions, corrections and assistance with various drafts of this
174article: .
175
176\end{document}