blob: bdcc05e4a6e12d9abb2e9a03f7a5b03d4367dd24 [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. Kuchling3e41b052005-03-01 00:53:46 +000031XXX describe this PEP.
Fred Drake2db76802004-12-01 05:05:47 +000032
33
34%======================================================================
35\section{Other Language Changes}
36
37Here are all of the changes that Python 2.5 makes to the core Python
38language.
39
40\begin{itemize}
Andrew M. Kuchling1cae3f52004-12-03 14:57:21 +000041
42\item The \function{min()} and \function{max()} built-in functions
43gained a \code{key} keyword argument analogous to the \code{key}
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +000044argument for \method{sort()}. This argument supplies a function
Andrew M. Kuchling1cae3f52004-12-03 14:57:21 +000045that takes a single argument and is called for every value in the list;
46\function{min()}/\function{max()} will return the element with the
47smallest/largest return value from this function.
48For example, to find the longest string in a list, you can do:
49
50\begin{verbatim}
51L = ['medium', 'longest', 'short']
52# Prints 'longest'
53print max(L, key=len)
54# Prints 'short', because lexicographically 'short' has the largest value
55print max(L)
56\end{verbatim}
57
58(Contributed by Steven Bethard and Raymond Hettinger.)
Fred Drake2db76802004-12-01 05:05:47 +000059
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +000060\item The list of base classes in a class definition can now be empty.
61As an example, this is now legal:
62
63\begin{verbatim}
64class C():
65 pass
66\end{verbatim}
67(Implemented by Brett Cannon.)
68
Fred Drake2db76802004-12-01 05:05:47 +000069\end{itemize}
70
71
72%======================================================================
73\subsection{Optimizations}
74
75\begin{itemize}
76
77\item Optimizations should be described here.
78
79\end{itemize}
80
81The net result of the 2.5 optimizations is that Python 2.5 runs the
Andrew M. Kuchling92e24952004-12-03 13:54:09 +000082pystone benchmark around XX\% faster than Python 2.4.
Fred Drake2db76802004-12-01 05:05:47 +000083
84
85%======================================================================
86\section{New, Improved, and Deprecated Modules}
87
88As usual, Python's standard library received a number of enhancements and
89bug fixes. Here's a partial list of the most notable changes, sorted
90alphabetically by module name. Consult the
91\file{Misc/NEWS} file in the source tree for a more
92complete list of changes, or look through the CVS logs for all the
93details.
94
95\begin{itemize}
96
Andrew M. Kuchling3e41b052005-03-01 00:53:46 +000097% the cPickle module no longer accepts the deprecated None option in the
98% args tuple returned by __reduce__().
99
100% csv module improvements
101
102% datetime.datetime() now has a strptime class method which can be used to
103% create datetime object using a string and format.
104
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +0000105\item The \function{nsmallest()} and
106\function{nlargest()} functions in the \module{heapq} module
107now support a \code{key} keyword argument similar to the one
108provided by the \function{min()}/\function{max()} functions
109and the \method{sort()} methods. For example:
110Example:
111
112\begin{verbatim}
113>>> import heapq
114>>> L = ["short", 'medium', 'longest', 'longer still']
115>>> heapq.nsmallest(2, L) # Return two lowest elements, lexicographically
116['longer still', 'longest']
117>>> heapq.nsmallest(2, L, key=len) # Return two shortest elements
118['short', 'medium']
119\end{verbatim}
120
121(Contributed by Raymond Hettinger.)
122
Andrew M. Kuchling511a3a82005-03-20 19:52:18 +0000123\item The \function{itertools.islice()} function now accepts
124\code{None} for the start and step arguments. This makes it more
125compatible with the attributes of slice objects, so that you can now write
126the following:
127
128\begin{verbatim}
129s = slice(5) # Create slice object
130itertools.islice(iterable, s.start, s.stop, s.step)
131\end{verbatim}
132
133(Contributed by Raymond Hettinger.)
Andrew M. Kuchling3e41b052005-03-01 00:53:46 +0000134
135\item New module: \module{spwd} provides functions for accessing the
136shadow password database on systems that support it.
137% XXX give example
138
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +0000139\item The \module{os} module underwent a number of changes. The
140\member{stat_float_times} variable now defaults to true, meaning that
141\function{os.stat()} will now return time values as floats. (This
142doesn't necessarily mean that \function{os.stat()} will return times
143that are precise to fractions of a second; not all systems support
144such precision.)
Andrew M. Kuchling3e41b052005-03-01 00:53:46 +0000145
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +0000146Also, constants named \member{os.SEEK_SET}, \member{os.SEEK_CUR}, and
147\member{os.SEEK_END} have been added; these are the parameters to the
148\function{os.lseek()} function.
Fred Drake2db76802004-12-01 05:05:47 +0000149
Andrew M. Kuchlinge9b1bf42005-03-20 19:26:30 +0000150\item The \class{TarFile} class in the \module{tarfile} module now has
151a \method{extractall()} method that extracts all members from the
152archive into the current working directory. It's also possible to set
153a different directory as the extraction target, and to unpack only a
154subset of the archive's members. (Contributed by Lars Gust\"abel.)
155
156
Fred Drake2db76802004-12-01 05:05:47 +0000157
158
159%======================================================================
160% whole new modules get described in \subsections here
161
162
163% ======================================================================
164\section{Build and C API Changes}
165
166Changes to Python's build process and to the C API include:
167
168\begin{itemize}
169
Andrew M. Kuchling2238fc62004-12-03 15:16:40 +0000170\item The \cfunction{PyRange_New()} function was removed. It was never documented,
171never used in the core code, and had dangerously lax error checking.
Fred Drake2db76802004-12-01 05:05:47 +0000172
173\end{itemize}
174
175
176%======================================================================
177\subsection{Port-Specific Changes}
178
179Platform-specific changes go here.
180
181
182%======================================================================
183\section{Other Changes and Fixes \label{section-other}}
184
185As usual, there were a bunch of other improvements and bugfixes
186scattered throughout the source tree. A search through the CVS change
187logs finds there were XXX patches applied and YYY bugs fixed between
Andrew M. Kuchling92e24952004-12-03 13:54:09 +0000188Python 2.4 and 2.5. Both figures are likely to be underestimates.
Fred Drake2db76802004-12-01 05:05:47 +0000189
190Some of the more notable changes are:
191
192\begin{itemize}
193
194\item Details go here.
195
196\end{itemize}
197
198
199%======================================================================
200\section{Porting to Python 2.5}
201
202This section lists previously described changes that may require
203changes to your code:
204
205\begin{itemize}
206
Andrew M. Kuchling3e41b052005-03-01 00:53:46 +0000207\item Some old deprecated modules (\module{statcache}, \module{tzparse},
208 \module{whrandom}) have been moved to \file{Lib/lib-old}.
Andrew M. Kuchling0c35db92005-03-20 20:06:49 +0000209You can get access to these modules again by adding the directory
210to your \code{sys.path}:
211
212\begin{verbatim}
213import os
214from distutils import sysconfig
215
216lib_dir = sysconfig.get_python_lib(standard_lib=True)
217old_dir = os.path.join(lib_dir, 'lib-old')
218sys.path.append(old_dir)
219\end{verbatim}
220
221Doing so is discouraged, however; it's better to update any code that
222still uses these modules.
Andrew M. Kuchling3e41b052005-03-01 00:53:46 +0000223
224% the pickle module no longer uses the deprecated bin parameter.
Fred Drake2db76802004-12-01 05:05:47 +0000225
226\end{itemize}
227
228
229%======================================================================
230\section{Acknowledgements \label{acks}}
231
232The author would like to thank the following people for offering
233suggestions, corrections and assistance with various drafts of this
234article: .
235
236\end{document}