blob: b7e404b3c67d909800006d20c7b118c6cbd655ee [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}
Fred Drakeb914ef02004-01-02 06:57:50 +00008\authoraddress{
9 \strong{Python Software Foundation}\\
10 Email: \email{amk@amk.ca}
11}
Fred Drakeed0fa3d2003-07-30 19:14:09 +000012
13\begin{document}
14\maketitle
15\tableofcontents
16
17This article explains the new features in Python 2.4. No release date
Raymond Hettingerd4462302003-11-26 17:52:45 +000018for Python 2.4 has been set; expect that this will happen mid-2004.
Fred Drakeed0fa3d2003-07-30 19:14:09 +000019
20While Python 2.3 was primarily a library development release, Python
212.4 may extend the core language and interpreter in
22as-yet-undetermined ways.
23
24This article doesn't attempt to provide a complete specification of
25the new features, but instead provides a convenient overview. For
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +000026full details, you should refer to the documentation for Python 2.4,
27such as the \citetitle[../lib/lib.html]{Python Library Reference} and
28the \citetitle[../ref/ref.html]{Python Reference Manual}.
Fred Drakeed0fa3d2003-07-30 19:14:09 +000029If you want to understand the complete implementation and design
30rationale, refer to the PEP for a particular new feature.
31
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +000032
Raymond Hettinger7e0282f2003-11-24 07:14:54 +000033%======================================================================
34\section{PEP 218: Built-In Set Objects}
35
36Two new built-in types, \function{set(iterable)} and
37\function{frozenset(iterable)} provide high speed data types for
38membership testing, for eliminating duplicates from sequences, and
39for mathematical operations like unions, intersections, differences,
40and symmetric differences.
41
42\begin{verbatim}
43>>> a = set('abracadabra') # form a set from a string
44>>> 'z' in a # fast membership testing
45False
46>>> a # unique letters in a
47set(['a', 'r', 'b', 'c', 'd'])
48>>> ''.join(a) # convert back into a string
49'arbcd'
Raymond Hettingerd4462302003-11-26 17:52:45 +000050
Raymond Hettinger7e0282f2003-11-24 07:14:54 +000051>>> b = set('alacazam') # form a second set
52>>> a - b # letters in a but not in b
53set(['r', 'd', 'b'])
54>>> a | b # letters in either a or b
55set(['a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'])
56>>> a & b # letters in both a and b
57set(['a', 'c'])
58>>> a ^ b # letters in a or b but not both
59set(['r', 'd', 'b', 'm', 'z', 'l'])
Raymond Hettingerd4462302003-11-26 17:52:45 +000060
Raymond Hettinger7e0282f2003-11-24 07:14:54 +000061>>> a.add('z') # add a new element
62>>> a.update('wxy') # add multiple new elements
63>>> a
64set(['a', 'c', 'b', 'd', 'r', 'w', 'y', 'x', 'z'])
65>>> a.remove('x') # take one element out
66>>> a
67set(['a', 'c', 'b', 'd', 'r', 'w', 'y', 'z'])
68\end{verbatim}
69
70The type \function{frozenset()} is an immutable version of \function{set()}.
71Since it is immutable and hashable, it may be used as a dictionary key or
72as a member of another set. Accordingly, it does not have methods
73like \method{add()} and \method{remove()} which could alter its contents.
74
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +000075% XXX what happens to the sets module?
Raymond Hettingered54d912003-12-31 01:59:18 +000076% The current thinking is that the sets module will be left alone.
77% That way, existing code will continue to run without alteration.
78% Also, the module provides an autoconversion feature not supported by set()
79% and frozenset().
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +000080
Raymond Hettinger7e0282f2003-11-24 07:14:54 +000081\begin{seealso}
82\seepep{218}{Adding a Built-In Set Object Type}{Originally proposed by
83Greg Wilson and ultimately implemented by Raymond Hettinger.}
84\end{seealso}
Fred Drakeed0fa3d2003-07-30 19:14:09 +000085
86%======================================================================
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +000087\section{PEP 237: Unifying Long Integers and Integers}
88
89XXX write this.
90
91%======================================================================
Andrew M. Kuchling1a420252003-11-08 15:58:49 +000092\section{PEP 322: Reverse Iteration}
Fred Drakeed0fa3d2003-07-30 19:14:09 +000093
Andrew M. Kuchling1a420252003-11-08 15:58:49 +000094A new built-in function, \function{reversed(seq)}, takes a sequence
95and returns an iterator that returns the elements of the sequence
96in reverse order.
97
98\begin{verbatim}
Raymond Hettingerbc3cba22003-11-12 16:39:30 +000099>>> for i in reversed(xrange(1,4)):
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000100... print i
101...
1023
1032
1041
105\end{verbatim}
106
Raymond Hettingerbc3cba22003-11-12 16:39:30 +0000107Compared to extended slicing, \code{range(1,4)[::-1]}, \function{reversed()}
108is easier to read, runs faster, and uses substantially less memory.
109
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000110Note that \function{reversed()} only accepts sequences, not arbitrary
Raymond Hettingerbc3cba22003-11-12 16:39:30 +0000111iterators. If you want to reverse an iterator, first convert it to
112a list with \function{list()}.
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000113
114\begin{verbatim}
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000115>>> input= open('/etc/passwd', 'r')
116>>> for line in reversed(list(input)):
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000117... print line
118...
119root:*:0:0:System Administrator:/var/root:/bin/tcsh
120 ...
121\end{verbatim}
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000122
Andrew M. Kuchlingf7a6b672003-11-08 16:05:37 +0000123\begin{seealso}
124\seepep{322}{Reverse Iteration}{Written and implemented by Raymond Hettinger.}
125
126\end{seealso}
127
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000128
129%======================================================================
130\section{Other Language Changes}
131
132Here are all of the changes that Python 2.4 makes to the core Python
133language.
134
135\begin{itemize}
Raymond Hettingerd4462302003-11-26 17:52:45 +0000136
137\item The string methods, \method{ljust()}, \method{rjust()}, and
Andrew M. Kuchling67087562003-11-26 18:03:48 +0000138\method{center()} now take an optional argument for specifying a
Raymond Hettingerd4462302003-11-26 17:52:45 +0000139fill character other than a space.
140
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000141\item Strings also gained an \method{rsplit()} method that
Raymond Hettingered54d912003-12-31 01:59:18 +0000142works like the \method{split()} method but splits from the end of
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000143the string.
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000144
145\begin{verbatim}
146>>> 'a b c'.split(None, 1)
147['a', 'b c']
148>>> 'a b c'.rsplit(None, 1)
149['a b', 'c']
150\end{verbatim}
151
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000152% Consider replacing the above example with one that is less
153% abstract and more suggestive of why the function is useful:
154%
155% >>> 'www.python.org'.split('.', 1)
156% ['www', 'python.org']
157% >>> 'www.python.org'.rsplit('.', 1)
158% ['www.python', 'org']
159
Andrew M. Kuchling2fb4d512003-10-21 12:31:16 +0000160\item The \method{sort()} method of lists gained three keyword
161arguments, \var{cmp}, \var{key}, and \var{reverse}. These arguments
162make some common usages of \method{sort()} simpler. All are optional.
163
164\var{cmp} is the same as the previous single argument to
165\method{sort()}; if provided, the value should be a comparison
166function that takes two arguments and returns -1, 0, or +1 depending
167on how the arguments compare.
168
169\var{key} should be a single-argument function that takes a list
170element and returns a comparison key for the element. The list is
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000171then sorted using the comparison keys. The following example sorts a
172list case-insensitively:
Andrew M. Kuchling2fb4d512003-10-21 12:31:16 +0000173
174\begin{verbatim}
175>>> L = ['A', 'b', 'c', 'D']
176>>> L.sort() # Case-sensitive sort
177>>> L
178['A', 'D', 'b', 'c']
179>>> L.sort(key=lambda x: x.lower())
180>>> L
181['A', 'b', 'c', 'D']
182>>> L.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
183>>> L
184['A', 'b', 'c', 'D']
185\end{verbatim}
186
187The last example, which uses the \var{cmp} parameter, is the old way
Raymond Hettingered54d912003-12-31 01:59:18 +0000188to perform a case-insensitive sort. It works but is slower than
Andrew M. Kuchling2fb4d512003-10-21 12:31:16 +0000189using a \var{key} parameter. Using \var{key} results in calling the
190\method{lower()} method once for each element in the list while using
191\var{cmp} will call the method twice for each comparison.
192
Andrew M. Kuchling981a9182003-11-13 21:33:26 +0000193For simple key functions and comparison functions, it is often
194possible to avoid a \keyword{lambda} expression by using an unbound
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000195method instead. For example, the above case-insensitive sort is best
196coded as:
197
198\begin{verbatim}
199>>> L.sort(key=str.lower)
200>>> L
201['A', 'b', 'c', 'D']
202\end{verbatim}
203
Andrew M. Kuchling2fb4d512003-10-21 12:31:16 +0000204The \var{reverse} parameter should have a Boolean value. If the value is
205\constant{True}, the list will be sorted into reverse order. Instead
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000206of \code{L.sort(lambda x,y: cmp(y.score, x.score))}, you can now write:
207\code{L.sort(key = lambda x: x.score, reverse=True)}.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000208
Andrew M. Kuchling981a9182003-11-13 21:33:26 +0000209The results of sorting are now guaranteed to be stable. This means
210that two entries with equal keys will be returned in the same order as
211they were input. For example, you can sort a list of people by name,
212and then sort the list by age, resulting in a list sorted by age where
213people with the same age are in name-sorted order.
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000214
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000215\item There is a new built-in function \function{sorted(iterable)} that works
Raymond Hettinger64958a12003-12-17 20:43:33 +0000216like the in-place \method{list.sort()} method but has been made suitable
217for use in expressions. The differences are:
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000218 \begin{itemize}
Raymond Hettinger7d1dd042003-11-12 16:42:10 +0000219 \item the input may be any iterable;
220 \item a newly formed copy is sorted, leaving the original intact; and
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000221 \item the expression returns the new sorted copy
222 \end{itemize}
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000223
224\begin{verbatim}
225>>> L = [9,7,8,3,2,4,1,6,5]
Raymond Hettinger64958a12003-12-17 20:43:33 +0000226>>> [10+i for i in sorted(L)] # usable in a list comprehension
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000227[11, 12, 13, 14, 15, 16, 17, 18, 19]
228>>> L = [9,7,8,3,2,4,1,6,5] # original is left unchanged
229[9,7,8,3,2,4,1,6,5]
Raymond Hettingerd4462302003-11-26 17:52:45 +0000230
Raymond Hettinger64958a12003-12-17 20:43:33 +0000231>>> sorted('Monte Python') # any iterable may be an input
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000232[' ', 'M', 'P', 'e', 'h', 'n', 'n', 'o', 'o', 't', 't', 'y']
Raymond Hettingerd4462302003-11-26 17:52:45 +0000233
234>>> # List the contents of a dict sorted by key values
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000235>>> colormap = dict(red=1, blue=2, green=3, black=4, yellow=5)
Raymond Hettinger64958a12003-12-17 20:43:33 +0000236>>> for k, v in sorted(colormap.iteritems()):
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000237... print k, v
238...
239black 4
240blue 2
241green 3
242red 1
243yellow 5
244
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000245\end{verbatim}
246
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000247\item The \function{zip()} built-in function and \function{itertools.izip()}
Andrew M. Kuchling67087562003-11-26 18:03:48 +0000248 now return an empty list instead of raising a \exception{TypeError}
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000249 exception if called with no arguments. This makes them more
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000250 suitable for use with variable length argument lists:
251
252\begin{verbatim}
253>>> def transpose(array):
254... return zip(*array)
255...
256>>> transpose([(1,2,3), (4,5,6)])
257[(1, 4), (2, 5), (3, 6)]
258>>> transpose([])
259[]
260\end{verbatim}
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000261
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000262\end{itemize}
263
264
265%======================================================================
266\subsection{Optimizations}
267
268\begin{itemize}
269
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000270\item \function{list()}, \function{tuple()}, \function{map()},
271 \function{filter()}, and \function{zip()} now run several times
272 faster with non-sequence arguments that supply a \method{__len__()}
273 method. Previously, the pre-sizing optimization only applied to
274 sequence arguments.
275
Raymond Hettinger23a0f4e2004-01-05 08:15:20 +0000276\item The methods \method{list.__getitem__()},
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000277 \method{dict.__getitem__()}, and \method{dict.__contains__()} are
278 are now implemented as \class{method_descriptor} objects rather
279 than \class{wrapper_descriptor} objects. This form of optimized
280 access doubles their performance and makes them more suitable for
Raymond Hettinger23a0f4e2004-01-05 08:15:20 +0000281 use as arguments to functionals:
282 \samp{map(mydict.__getitem__, keylist)}.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000283
284\end{itemize}
285
286The net result of the 2.4 optimizations is that Python 2.4 runs the
287pystone benchmark around XX\% faster than Python 2.3 and YY\% faster
288than Python 2.2.
289
290
291%======================================================================
292\section{New, Improved, and Deprecated Modules}
293
294As usual, Python's standard library received a number of enhancements and
295bug fixes. Here's a partial list of the most notable changes, sorted
296alphabetically by module name. Consult the
297\file{Misc/NEWS} file in the source tree for a more
298complete list of changes, or look through the CVS logs for all the
299details.
300
301\begin{itemize}
302
Andrew M. Kuchling69f31eb2003-08-13 23:11:04 +0000303\item The \module{curses} modules now supports the ncurses extension
304 \function{use_default_colors()}. On platforms where the terminal
305 supports transparency, this makes it possible to use a transparent background.
306 (Contributed by J\"org Lehmann.)
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000307
Raymond Hettinger0c410272004-01-05 10:13:35 +0000308\item The \module{bisect} module now has an underlying C implementation
309 for improved performance.
310 (Contributed by Dmitry Vasiliev.)
311
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000312\item The \module{heapq} module has been converted to C. The resulting
313 ten-fold improvement in speed makes the module suitable for handling
314 high volumes of data.
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000315
Andrew M. Kuchlingdff9dbd2003-11-20 22:22:19 +0000316\item The \module{imaplib} module now supports IMAP's THREAD command.
317(Contributed by Yves Dionne.)
318
Andrew M. Kuchlingad809552003-12-06 23:19:23 +0000319\item The \module{itertools} module gained a
320 \function{groupby(\var{iterable}\optional{, \var{func}})} function,
321 inspired by the GROUP BY clause from SQL.
322 \var{iterable} returns a succession of elements, and the optional
323 \var{func} is a function that takes an element and returns a key
324 value; if omitted, the key is simply the element itself.
325 \function{groupby()} then groups the elements into subsequences
326 which have matching values of the key, and returns a series of 2-tuples
327 containing the key value and an iterator over the subsequence.
328
329Here's an example. The \var{key} function simply returns whether a
330number is even or odd, so the result of \function{groupby()} is to
331return consecutive runs of odd or even numbers.
332
333\begin{verbatim}
334>>> import itertools
335>>> L = [2,4,6, 7,8,9,11, 12, 14]
336>>> for key_val, it in itertools.groupby(L, lambda x: x % 2):
337... print key_val, list(it)
338...
3390 [2, 4, 6]
3401 [7]
3410 [8]
3421 [9, 11]
3430 [12, 14]
344>>>
345\end{verbatim}
346
Raymond Hettingerfeb78c92003-12-12 13:13:47 +0000347Like its SQL counterpart, \function{groupby()} is typically used with
348sorted input. The logic for \function{groupby()} is similar to the
349\UNIX{} \code{uniq} filter which makes it handy for eliminating,
350counting, or identifying duplicate elements:
351
352\begin{verbatim}
353>>> word = 'abracadabra'
Raymond Hettingered54d912003-12-31 01:59:18 +0000354>>> letters = sorted(word) # Turn string into a sorted list of letters
Raymond Hettinger64958a12003-12-17 20:43:33 +0000355>>> letters
Andrew M. Kuchling4612bc52003-12-16 20:59:37 +0000356['a', 'a', 'a', 'a', 'a', 'b', 'b', 'c', 'd', 'r', 'r']
Raymond Hettingered54d912003-12-31 01:59:18 +0000357>>> [k for k, g in groupby(letters)] # List unique letters
Raymond Hettingerfeb78c92003-12-12 13:13:47 +0000358['a', 'b', 'c', 'd', 'r']
Raymond Hettingered54d912003-12-31 01:59:18 +0000359>>> [(k, len(list(g))) for k, g in groupby(letters)] # Count letter occurences
Raymond Hettingerfeb78c92003-12-12 13:13:47 +0000360[('a', 5), ('b', 2), ('c', 1), ('d', 1), ('r', 2)]
Raymond Hettingered54d912003-12-31 01:59:18 +0000361>>> [k for k, g in groupby(letters) if len(list(g)) > 1] # List duplicated letters
Raymond Hettingerfeb78c92003-12-12 13:13:47 +0000362['a', 'b', 'r']
363\end{verbatim}
364
Raymond Hettingered54d912003-12-31 01:59:18 +0000365\item \module{itertools} also gained a function named
366\function{tee(\var{iterator}, \var{N})} that returns \var{N} independent
367iterators that replicate \var{iterator}. If \var{N} is omitted, the
368default is 2.
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000369
370\begin{verbatim}
371>>> L = [1,2,3]
372>>> i1, i2 = itertools.tee(L)
373>>> i1,i2
374(<itertools.tee object at 0x402c2080>, <itertools.tee object at 0x402c2090>)
Raymond Hettingered54d912003-12-31 01:59:18 +0000375>>> list(i1) # Run the first iterator to exhaustion
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000376[1, 2, 3]
Raymond Hettingered54d912003-12-31 01:59:18 +0000377>>> list(i2) # Run the second iterator to exhaustion
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000378[1, 2, 3]
379>\end{verbatim}
380
381Note that \function{tee()} has to keep copies of the values returned
Raymond Hettingered54d912003-12-31 01:59:18 +0000382by the iterator; in the worst case, it may need to keep all of them.
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000383This should therefore be used carefully if the leading iterator
Raymond Hettingered54d912003-12-31 01:59:18 +0000384can run far ahead of the trailing iterator in a long stream of inputs.
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000385If the separation is large, then it becomes preferable to use
Raymond Hettingered54d912003-12-31 01:59:18 +0000386\function{list()} instead. When the iterators track closely with one
387another, \function{tee()} is ideal. Possible applications include
388bookmarking, windowing, or lookahead iterators.
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000389
Andrew M. Kuchlingdff9dbd2003-11-20 22:22:19 +0000390\item A new \function{getsid()} function was added to the
391\module{posix} module that underlies the \module{os} module.
392(Contributed by J. Raynor.)
393
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000394\item The \module{operator} module gained two new functions,
395\function{attrgetter(\var{attr})} and \function{itemgetter(\var{index})}.
396Both functions return callables that take a single argument and return
Raymond Hettingered54d912003-12-31 01:59:18 +0000397the corresponding attribute or item; these callables make excellent
398data extractors when used with \function{map()} or \function{sorted()}.
399For example:
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000400
401\begin{verbatim}
Raymond Hettingered54d912003-12-31 01:59:18 +0000402>>> L = [('c', 2), ('d', 1), ('a', 4), ('b', 3)]
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000403>>> map(operator.itemgetter(0), L)
404['c', 'd', 'a', 'b']
405>>> map(operator.itemgetter(1), L)
Raymond Hettingered54d912003-12-31 01:59:18 +0000406[2, 1, 4, 3]
407>>> sorted(L, key=operator.itemgetter(1)) # Sort list by second tuple item
408[('d', 1), ('c', 2), ('b', 3), ('a', 4)]
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000409\end{verbatim}
410
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000411\item The \module{random} module has a new method called \method{getrandbits(N)}
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000412 which returns an N-bit long integer. This method supports the existing
413 \method{randrange()} method, making it possible to efficiently generate
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000414 arbitrarily large random numbers.
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000415
416\item The regular expression language accepted by the \module{re} module
417 was extended with simple conditional expressions, written as
418 \code{(?(\var{group})\var{A}|\var{B})}. \var{group} is either a
419 numeric group ID or a group name defined with \code{(?P<group>...)}
420 earlier in the expression. If the specified group matched, the
421 regular expression pattern \var{A} will be tested against the string; if
422 the group didn't match, the pattern \var{B} will be used instead.
Andrew M. Kuchling69f31eb2003-08-13 23:11:04 +0000423
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000424\end{itemize}
425
426
427%======================================================================
428% whole new modules get described in \subsections here
429
430
431% ======================================================================
432\section{Build and C API Changes}
433
434Changes to Python's build process and to the C API include:
435
436\begin{itemize}
437
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000438 \item Three new convenience macros were added for common return
439 values from extension functions: \csimplemacro{Py_RETURN_NONE},
440 \csimplemacro{Py_RETURN_TRUE}, and \csimplemacro{Py_RETURN_FALSE}.
441
442 \item A new function, \cfunction{PyTuple_Pack(N, obj1, obj2, ...,
443 objN)}, constructs tuples from a variable length argument list of
444 Python objects.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000445
Andrew M. Kuchling2ce1d472003-11-26 18:05:26 +0000446 \item A new function, \cfunction{PyDict_Contains(d, k)}, implements
447 fast dictionary lookups without masking exceptions raised during the
448 look-up process.
Raymond Hettingerd4462302003-11-26 17:52:45 +0000449
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000450 \item A new method flag, \code{METH_COEXISTS}, allows a function
451 defined in slots to co-exist with a PyCFunction having the same name.
452 This can halve the access to time to a method such as
453 \method{set.__contains__()}
454
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000455\end{itemize}
456
457
458%======================================================================
459\subsection{Port-Specific Changes}
460
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000461\begin{itemize}
462
463\item The Windows port now builds under MSVC++ 7.1 as well as version 6.
464
465\end{itemize}
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000466
467
468%======================================================================
469\section{Other Changes and Fixes \label{section-other}}
470
471As usual, there were a bunch of other improvements and bugfixes
472scattered throughout the source tree. A search through the CVS change
473logs finds there were XXX patches applied and YYY bugs fixed between
474Python 2.3 and 2.4. Both figures are likely to be underestimates.
475
476Some of the more notable changes are:
477
478\begin{itemize}
479
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000480\item The \module{timeit} module now automatically disables periodic
481 garbarge collection during the timing loop. This change makes
482 consecutive timings more comparable.
483
484\item The \module{base64} module now has more complete RFC 3548 support
485 for Base64, Base32, and Base16 encoding and decoding, including
486 optional case folding and optional alternative alphabets.
487 (Contributed by Barry Warsaw.)
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000488
489\end{itemize}
490
491
492%======================================================================
493\section{Porting to Python 2.4}
494
495This section lists previously described changes that may require
496changes to your code:
497
498\begin{itemize}
499
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000500\item The \function{zip()} built-in function and \function{itertools.izip()}
501 now return an empty list instead of raising a \exception{TypeError}
502 exception if called with no arguments.
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000503
504\item \function{dircache.listdir()} now passes exceptions to the caller
505 instead of returning empty lists.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000506
507\end{itemize}
508
509
510%======================================================================
511\section{Acknowledgements \label{acks}}
512
513The author would like to thank the following people for offering
514suggestions, corrections and assistance with various drafts of this
Andrew M. Kuchling981a9182003-11-13 21:33:26 +0000515article: Raymond Hettinger.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000516
517\end{document}