blob: 869eb58712055e79ce87122022626faf0a8b363e [file] [log] [blame]
Fred Drake2db76802004-12-01 05:05:47 +00001\documentclass{howto}
2\usepackage{distutils}
3% $Id$
4
Fred Drake2db76802004-12-01 05:05:47 +00005
6\title{What's New in Python 2.5}
7\release{0.0}
Andrew M. Kuchling92e24952004-12-03 13:54:09 +00008\author{A.M. Kuchling}
9\authoraddress{\email{amk@amk.ca}}
Fred Drake2db76802004-12-01 05:05:47 +000010
11\begin{document}
12\maketitle
13\tableofcontents
14
15This article explains the new features in Python 2.5. No release date
Andrew M. Kuchling92e24952004-12-03 13:54:09 +000016for Python 2.5 has been set; it will probably be released in late 2005.
Fred Drake2db76802004-12-01 05:05:47 +000017
18% Compare with previous release in 2 - 3 sentences here.
19
20This article doesn't attempt to provide a complete specification of
21the new features, but instead provides a convenient overview. For
22full details, you should refer to the documentation for Python 2.5.
23% add hyperlink when the documentation becomes available online.
24If you want to understand the complete implementation and design
25rationale, refer to the PEP for a particular new feature.
26
27
28%======================================================================
Andrew M. Kuchling3e41b052005-03-01 00:53:46 +000029\section{PEP 309: Partial Function Application}
Fred Drake2db76802004-12-01 05:05:47 +000030
Andrew M. Kuchlingb1c96fd2005-03-20 21:42:04 +000031For programs written in a functional style, it can be useful to
32construct variants of existing functions that have some of the
33parameters filled in. This is called ``partial function application''.
34The new \module{functional} module contains a \class{partial} class
35that provides partial application.
36
37The \module{functional} module is intended to contain tools for
38functional-style programming. Currently it only contains
39\class{partial}, but new functions will probably be added in future
40versions of Python.
41
42% XXX write rest of this
43% XXX add example from my GTk programming
44
45
46\begin{seealso}
47
48\seepep{309}{Partial Function Application}{PEP proposed and written by
49Peter Harris; implemented by Hye-Shik Chang, with adaptations by
50Raymond Hettinger.}
51
52\end{seealso}
Fred Drake2db76802004-12-01 05:05:47 +000053
54
55%======================================================================
56\section{Other Language Changes}
57
58Here are all of the changes that Python 2.5 makes to the core Python
59language.
60
61\begin{itemize}
Andrew M. Kuchling1cae3f52004-12-03 14:57:21 +000062
63\item The \function{min()} and \function{max()} built-in functions
64gained a \code{key} keyword argument analogous to the \code{key}
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +000065argument for \method{sort()}. This argument supplies a function
Andrew M. Kuchling1cae3f52004-12-03 14:57:21 +000066that takes a single argument and is called for every value in the list;
67\function{min()}/\function{max()} will return the element with the
68smallest/largest return value from this function.
69For example, to find the longest string in a list, you can do:
70
71\begin{verbatim}
72L = ['medium', 'longest', 'short']
73# Prints 'longest'
74print max(L, key=len)
75# Prints 'short', because lexicographically 'short' has the largest value
76print max(L)
77\end{verbatim}
78
79(Contributed by Steven Bethard and Raymond Hettinger.)
Fred Drake2db76802004-12-01 05:05:47 +000080
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +000081\item The list of base classes in a class definition can now be empty.
82As an example, this is now legal:
83
84\begin{verbatim}
85class C():
86 pass
87\end{verbatim}
88(Implemented by Brett Cannon.)
89
Fred Drake2db76802004-12-01 05:05:47 +000090\end{itemize}
91
92
93%======================================================================
94\subsection{Optimizations}
95
96\begin{itemize}
97
98\item Optimizations should be described here.
99
100\end{itemize}
101
102The net result of the 2.5 optimizations is that Python 2.5 runs the
Andrew M. Kuchling92e24952004-12-03 13:54:09 +0000103pystone benchmark around XX\% faster than Python 2.4.
Fred Drake2db76802004-12-01 05:05:47 +0000104
105
106%======================================================================
107\section{New, Improved, and Deprecated Modules}
108
109As usual, Python's standard library received a number of enhancements and
110bug fixes. Here's a partial list of the most notable changes, sorted
111alphabetically by module name. Consult the
112\file{Misc/NEWS} file in the source tree for a more
113complete list of changes, or look through the CVS logs for all the
114details.
115
116\begin{itemize}
117
Andrew M. Kuchling3e41b052005-03-01 00:53:46 +0000118% the cPickle module no longer accepts the deprecated None option in the
119% args tuple returned by __reduce__().
120
121% csv module improvements
122
123% datetime.datetime() now has a strptime class method which can be used to
124% create datetime object using a string and format.
125
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +0000126\item The \function{nsmallest()} and
127\function{nlargest()} functions in the \module{heapq} module
128now support a \code{key} keyword argument similar to the one
129provided by the \function{min()}/\function{max()} functions
130and the \method{sort()} methods. For example:
131Example:
132
133\begin{verbatim}
134>>> import heapq
135>>> L = ["short", 'medium', 'longest', 'longer still']
136>>> heapq.nsmallest(2, L) # Return two lowest elements, lexicographically
137['longer still', 'longest']
138>>> heapq.nsmallest(2, L, key=len) # Return two shortest elements
139['short', 'medium']
140\end{verbatim}
141
142(Contributed by Raymond Hettinger.)
143
Andrew M. Kuchling511a3a82005-03-20 19:52:18 +0000144\item The \function{itertools.islice()} function now accepts
145\code{None} for the start and step arguments. This makes it more
146compatible with the attributes of slice objects, so that you can now write
147the following:
148
149\begin{verbatim}
150s = slice(5) # Create slice object
151itertools.islice(iterable, s.start, s.stop, s.step)
152\end{verbatim}
153
154(Contributed by Raymond Hettinger.)
Andrew M. Kuchling3e41b052005-03-01 00:53:46 +0000155
156\item New module: \module{spwd} provides functions for accessing the
157shadow password database on systems that support it.
158% XXX give example
159
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +0000160\item The \module{os} module underwent a number of changes. The
161\member{stat_float_times} variable now defaults to true, meaning that
162\function{os.stat()} will now return time values as floats. (This
163doesn't necessarily mean that \function{os.stat()} will return times
164that are precise to fractions of a second; not all systems support
165such precision.)
Andrew M. Kuchling3e41b052005-03-01 00:53:46 +0000166
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +0000167Also, constants named \member{os.SEEK_SET}, \member{os.SEEK_CUR}, and
168\member{os.SEEK_END} have been added; these are the parameters to the
169\function{os.lseek()} function.
Fred Drake2db76802004-12-01 05:05:47 +0000170
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +0000171\item The \class{TarFile} class in the \module{tarfile} module now has
172a \method{extractall()} method that extracts all members from the
173archive into the current working directory. It's also possible to set
174a different directory as the extraction target, and to unpack only a
175subset of the archive's members. (Contributed by Lars Gust\"abel.)
176
177
Fred Drake2db76802004-12-01 05:05:47 +0000178
179
180%======================================================================
181% whole new modules get described in \subsections here
182
183
184% ======================================================================
185\section{Build and C API Changes}
186
187Changes to Python's build process and to the C API include:
188
189\begin{itemize}
190
Andrew M. Kuchling2238fc62004-12-03 15:16:40 +0000191\item The \cfunction{PyRange_New()} function was removed. It was never documented,
192never used in the core code, and had dangerously lax error checking.
Fred Drake2db76802004-12-01 05:05:47 +0000193
194\end{itemize}
195
196
197%======================================================================
198\subsection{Port-Specific Changes}
199
200Platform-specific changes go here.
201
202
203%======================================================================
204\section{Other Changes and Fixes \label{section-other}}
205
206As usual, there were a bunch of other improvements and bugfixes
207scattered throughout the source tree. A search through the CVS change
208logs finds there were XXX patches applied and YYY bugs fixed between
Andrew M. Kuchling92e24952004-12-03 13:54:09 +0000209Python 2.4 and 2.5. Both figures are likely to be underestimates.
Fred Drake2db76802004-12-01 05:05:47 +0000210
211Some of the more notable changes are:
212
213\begin{itemize}
214
215\item Details go here.
216
217\end{itemize}
218
219
220%======================================================================
221\section{Porting to Python 2.5}
222
223This section lists previously described changes that may require
224changes to your code:
225
226\begin{itemize}
227
Andrew M. Kuchling3e41b052005-03-01 00:53:46 +0000228\item Some old deprecated modules (\module{statcache}, \module{tzparse},
229 \module{whrandom}) have been moved to \file{Lib/lib-old}.
Andrew M. Kuchling0c35db92005-03-20 20:06:49 +0000230You can get access to these modules again by adding the directory
231to your \code{sys.path}:
232
233\begin{verbatim}
234import os
235from distutils import sysconfig
236
237lib_dir = sysconfig.get_python_lib(standard_lib=True)
238old_dir = os.path.join(lib_dir, 'lib-old')
239sys.path.append(old_dir)
240\end{verbatim}
241
242Doing so is discouraged, however; it's better to update any code that
243still uses these modules.
Andrew M. Kuchling3e41b052005-03-01 00:53:46 +0000244
245% the pickle module no longer uses the deprecated bin parameter.
Fred Drake2db76802004-12-01 05:05:47 +0000246
247\end{itemize}
248
249
250%======================================================================
251\section{Acknowledgements \label{acks}}
252
253The author would like to thank the following people for offering
254suggestions, corrections and assistance with various drafts of this
255article: .
256
257\end{document}