blob: dfe509d4cb34ae895af887233e7468bde7145408 [file] [log] [blame]
Fred Drakeed0fa3d2003-07-30 19:14:09 +00001\documentclass{howto}
2\usepackage{distutils}
3% $Id$
4
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +00005% Don't write extensive text for new sections; I'll do that.
6% Feel free to add commented-out reminders of things that need
7% to be covered. --amk
8
Fred Drakeed0fa3d2003-07-30 19:14:09 +00009\title{What's New in Python 2.4}
10\release{0.0}
11\author{A.M.\ Kuchling}
Fred Drakeb914ef02004-01-02 06:57:50 +000012\authoraddress{
13 \strong{Python Software Foundation}\\
14 Email: \email{amk@amk.ca}
15}
Fred Drakeed0fa3d2003-07-30 19:14:09 +000016
17\begin{document}
18\maketitle
19\tableofcontents
20
Raymond Hettinger6e1fd2f2004-05-19 22:30:25 +000021This article explains the new features in Python 2.4. The release
22date is expected to be around September 2004.
Fred Drakeed0fa3d2003-07-30 19:14:09 +000023
24While Python 2.3 was primarily a library development release, Python
252.4 may extend the core language and interpreter in
26as-yet-undetermined ways.
27
28This article doesn't attempt to provide a complete specification of
29the new features, but instead provides a convenient overview. For
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +000030full details, you should refer to the documentation for Python 2.4,
31such as the \citetitle[../lib/lib.html]{Python Library Reference} and
32the \citetitle[../ref/ref.html]{Python Reference Manual}.
Fred Drakeed0fa3d2003-07-30 19:14:09 +000033If you want to understand the complete implementation and design
34rationale, refer to the PEP for a particular new feature.
35
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +000036
Raymond Hettinger7e0282f2003-11-24 07:14:54 +000037%======================================================================
38\section{PEP 218: Built-In Set Objects}
39
Fred Drake56fcc232004-05-06 02:55:35 +000040Two new built-in types, \function{set(\var{iterable})} and
41\function{frozenset(\var{iterable})} provide high speed data types for
Raymond Hettinger7e0282f2003-11-24 07:14:54 +000042membership testing, for eliminating duplicates from sequences, and
43for mathematical operations like unions, intersections, differences,
44and symmetric differences.
45
46\begin{verbatim}
47>>> a = set('abracadabra') # form a set from a string
48>>> 'z' in a # fast membership testing
49False
50>>> a # unique letters in a
51set(['a', 'r', 'b', 'c', 'd'])
52>>> ''.join(a) # convert back into a string
53'arbcd'
Raymond Hettingerd4462302003-11-26 17:52:45 +000054
Raymond Hettinger7e0282f2003-11-24 07:14:54 +000055>>> b = set('alacazam') # form a second set
56>>> a - b # letters in a but not in b
57set(['r', 'd', 'b'])
58>>> a | b # letters in either a or b
59set(['a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'])
60>>> a & b # letters in both a and b
61set(['a', 'c'])
62>>> a ^ b # letters in a or b but not both
63set(['r', 'd', 'b', 'm', 'z', 'l'])
Raymond Hettingerd4462302003-11-26 17:52:45 +000064
Raymond Hettinger7e0282f2003-11-24 07:14:54 +000065>>> a.add('z') # add a new element
66>>> a.update('wxy') # add multiple new elements
67>>> a
68set(['a', 'c', 'b', 'd', 'r', 'w', 'y', 'x', 'z'])
69>>> a.remove('x') # take one element out
70>>> a
71set(['a', 'c', 'b', 'd', 'r', 'w', 'y', 'z'])
72\end{verbatim}
73
74The type \function{frozenset()} is an immutable version of \function{set()}.
75Since it is immutable and hashable, it may be used as a dictionary key or
76as a member of another set. Accordingly, it does not have methods
77like \method{add()} and \method{remove()} which could alter its contents.
78
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +000079% XXX what happens to the sets module?
Raymond Hettingered54d912003-12-31 01:59:18 +000080% The current thinking is that the sets module will be left alone.
81% That way, existing code will continue to run without alteration.
82% Also, the module provides an autoconversion feature not supported by set()
83% and frozenset().
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +000084
Raymond Hettinger7e0282f2003-11-24 07:14:54 +000085\begin{seealso}
86\seepep{218}{Adding a Built-In Set Object Type}{Originally proposed by
87Greg Wilson and ultimately implemented by Raymond Hettinger.}
88\end{seealso}
Fred Drakeed0fa3d2003-07-30 19:14:09 +000089
90%======================================================================
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +000091\section{PEP 237: Unifying Long Integers and Integers}
92
Andrew M. Kuchlingd4be86c2004-07-04 01:44:04 +000093The lengthy transition process for the PEP, begun with Python 2.2,
94takes another step forward in Python 2.4. In 2.3, certain integer
95operations that would behave differently after int/long unification
96triggered \exception{FutureWarning} warnings and returned values
97limited to 32 or 64 bits. In 2.4, these expressions no longer produce
98a warning, but they now produce a different value that's a long
99integer.
100
101The problematic expressions are primarily left shifts and lengthy
102hexadecimal and octal constants. For example, \code{2 << 32} is one
103expression that results in a warning in 2.3, evaluating to 0 on 32-bit
104platforms. In Python 2.4, this expression now returns 8589934592.
105
106
107\begin{seealso}
108\seepep{237}{Unifying Long Integers and Integers}{Original PEP
109written by Moshe Zadka and Gvr. The changes for 2.4 were implemented by
110Kalle Svensson.}
111\end{seealso}
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000112
113%======================================================================
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000114\section{PEP 289: Generator Expressions}
Raymond Hettinger354433a2004-05-19 08:20:33 +0000115
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000116The iterator feature introduced in Python 2.2 makes it easier to write
117programs that loop through large data sets without having the entire
118data set in memory at one time. Programmers can use iterators and the
119\module{itertools} module to write code in a fairly functional style.
120
121The fly in the ointment has been list comprehensions, because they
122produce a Python list object containing all of the items, unavoidably
123pulling them all into memory. When trying to write a program using the functional approach, it would be natural to write something like:
Raymond Hettinger354433a2004-05-19 08:20:33 +0000124
125\begin{verbatim}
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000126links = [link for link in get_all_links() if not link.followed]
127for link in links:
128 ...
Raymond Hettinger354433a2004-05-19 08:20:33 +0000129\end{verbatim}
130
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000131instead of
Raymond Hettinger354433a2004-05-19 08:20:33 +0000132
133\begin{verbatim}
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000134for link in get_all_links():
135 if link.followed:
136 continue
137 ...
138\end{verbatim}
Raymond Hettinger354433a2004-05-19 08:20:33 +0000139
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000140The first form is more concise and perhaps more readable, but if
141you're dealing with a large number of link objects the second form
142would have to be used.
Raymond Hettinger354433a2004-05-19 08:20:33 +0000143
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000144Generator expressions work similarly to list comprehensions but don't
145materialize the entire list; instead they create a generator that will
146return elements one by one. The above example could be written as:
Raymond Hettinger354433a2004-05-19 08:20:33 +0000147
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000148\begin{verbatim}
149links = (link for link in get_all_links() if not link.followed)
150for link in links:
151 ...
152\end{verbatim}
Raymond Hettinger170a6222004-05-19 19:45:19 +0000153
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000154Generator expressions always have to be written inside parentheses, as
155in the above example. The parentheses signalling a function call also
156count, so if you want to create a iterator that will be immediately
157passed to a function you could write:
Raymond Hettinger170a6222004-05-19 19:45:19 +0000158
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000159\begin{verbatim}
160print sum(obj.count for obj in list_all_objects())
161\end{verbatim}
Raymond Hettinger170a6222004-05-19 19:45:19 +0000162
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000163There are some small differences from list comprehensions. Most
164notably, the loop variable (\var{obj} in the above example) is not
165accessible outside of the generator expression. List comprehensions
166leave the variable assigned to its last value; future versions of
167Python will change this, making list comprehensions match generator
168expressions in this respect.
Raymond Hettinger354433a2004-05-19 08:20:33 +0000169
170\begin{seealso}
171\seepep{289}{Generator Expressions}{Proposed by Raymond Hettinger and
172implemented by Jiwon Seo with early efforts steered by Hye-Shik Chang.}
173\end{seealso}
174
175%======================================================================
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000176\section{PEP 322: Reverse Iteration}
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000177
Fred Drake56fcc232004-05-06 02:55:35 +0000178A new built-in function, \function{reversed(\var{seq})}, takes a sequence
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000179and returns an iterator that returns the elements of the sequence
180in reverse order.
181
182\begin{verbatim}
Raymond Hettingerbc3cba22003-11-12 16:39:30 +0000183>>> for i in reversed(xrange(1,4)):
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000184... print i
185...
1863
1872
1881
189\end{verbatim}
190
Raymond Hettingerbc3cba22003-11-12 16:39:30 +0000191Compared to extended slicing, \code{range(1,4)[::-1]}, \function{reversed()}
192is easier to read, runs faster, and uses substantially less memory.
193
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000194Note that \function{reversed()} only accepts sequences, not arbitrary
Raymond Hettingerbc3cba22003-11-12 16:39:30 +0000195iterators. If you want to reverse an iterator, first convert it to
196a list with \function{list()}.
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000197
198\begin{verbatim}
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000199>>> input= open('/etc/passwd', 'r')
200>>> for line in reversed(list(input)):
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000201... print line
202...
203root:*:0:0:System Administrator:/var/root:/bin/tcsh
204 ...
205\end{verbatim}
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000206
Andrew M. Kuchlingf7a6b672003-11-08 16:05:37 +0000207\begin{seealso}
208\seepep{322}{Reverse Iteration}{Written and implemented by Raymond Hettinger.}
209
210\end{seealso}
211
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000212
213%======================================================================
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000214\section{PEP 327: Decimal Data Type}
215
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000216Python has always supported floating-point (FP) numbers as a data
217type, based on the underlying C \ctype{double} type. However, while
218most programming languages provide a floating-point type, most people
219(even programmers) are unaware that computing with floating-point
220numbers entails certain unavoidable inaccuracies. The new decimal
221type provides a way to avoid these inaccuracies.
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000222
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000223\subsection{Why is Decimal needed?}
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000224
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000225The limitations arise from the representation used for floating-point numbers.
226FP numbers are made up of three components:
227
228\begin{itemize}
229\item The sign, which is -1 or +1.
230\item The mantissa, which is a single-digit binary number
231followed by a fractional part. For example, \code{1.01} in base-2 notation
232is \code{1 + 0/2 + 1/4}, or 1.25 in decimal notation.
233\item The exponent, which tells where the decimal point is located in the number represented.
234\end{itemize}
235
236For example, the number 1.25 has sign +1, mantissa 1.01 (in binary),
237and exponent of 0 (the decimal point doesn't need to be shifted). The
238number 5 has the same sign and mantissa, but the exponent is 2
239because the mantissa is multiplied by 4 (2 to the power of the exponent 2).
240
241Modern systems usually provide floating-point support that conforms to
242a relevant standard called IEEE 754. C's \ctype{double} type is
243usually implemented as a 64-bit IEEE 754 number, which uses 52 bits of
244space for the mantissa. This means that numbers can only be specified
245to 52 bits of precision. If you're trying to represent numbers whose
246expansion repeats endlessly, the expansion is cut off after 52 bits.
247Unfortunately, most software needs to produce output in base 10, and
248base 10 often gives rise to such repeating decimals. For example, 1.1
249decimal is binary \code{1.0001100110011 ...}; .1 = 1/16 + 1/32 + 1/256
250plus an infinite number of additional terms. IEEE 754 has to chop off
251that infinitely repeated decimal after 52 digits, so the
252representation is slightly inaccurate.
253
254Sometimes you can see this inaccuracy when the number is printed:
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000255\begin{verbatim}
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000256>>> 1.1
2571.1000000000000001
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000258\end{verbatim}
259
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000260The inaccuracy isn't always visible when you print the number because
261the FP-to-decimal-string conversion is provided by the C library, and
262most C libraries try to produce sensible output, but the inaccuracy is
263still there and subsequent operations can magnify the error.
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000264
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000265For many applications this doesn't matter. If I'm plotting points and
266displaying them on my monitor, the difference between 1.1 and
2671.1000000000000001 is too small to be visible. Reports often limit
268output to a certain number of decimal places, and if you round the
269number to two or three or even eight decimal places, the error is
270never apparent. However, for applications where it does matter,
271it's a lot of work to implement your own custom arithmetic routines.
272
273\subsection{The \class{Decimal} type}
274
275A new module, \module{decimal}, was added to Python's standard library.
276It contains two classes, \class{Decimal} and \class{Context}.
277\class{Decimal} instances represent numbers, and
278\class{Context} instances are used to wrap up various settings such as the precision and default rounding mode.
279
280\class{Decimal} instances, like regular Python integers and FP numbers, are immutable; once they've been created, you can't change the value it represents.
281\class{Decimal} instances can be created from integers or strings:
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000282
283\begin{verbatim}
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000284>>> import decimal
285>>> decimal.Decimal(1972)
286Decimal("1972")
287>>> decimal.Decimal("1.1")
288Decimal("1.1")
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000289\end{verbatim}
290
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000291You can also provide tuples containing the sign, mantissa represented
292as a tuple of decimal digits, and exponent:
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000293
294\begin{verbatim}
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000295>>> decimal.Decimal((1, (1, 4, 7, 5), -2))
296Decimal("-14.75")
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000297\end{verbatim}
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000298
299Cautionary note: the sign bit is a Boolean value, so 0 is positive and 1 is negative.
300
301Floating-point numbers posed a bit of a problem: should the FP number
302representing 1.1 turn into the decimal number for exactly 1.1, or for
3031.1 plus whatever inaccuracies are introduced? The decision was to
304leave such a conversion out of the API. Instead, you should convert
305the floating-point number into a string using the desired precision and
306pass the string to the \class{Decimal} constructor:
307
308\begin{verbatim}
309>>> f = 1.1
310>>> decimal.Decimal(str(f))
311Decimal("1.1")
312>>> decimal.Decimal(repr(f))
313Decimal("1.1000000000000001")
314\end{verbatim}
315
316Once you have \class{Decimal} instances, you can perform the usual
317mathematical operations on them. One limitation: exponentiation
318requires an integer exponent:
319
320\begin{verbatim}
321>>> a = decimal.Decimal('35.72')
322>>> b = decimal.Decimal('1.73')
323>>> a+b
324Decimal("37.45")
325>>> a-b
326Decimal("33.99")
327>>> a*b
328Decimal("61.7956")
329>>> a/b
330Decimal("20.6473988")
331>>> a ** 2
332Decimal("1275.9184")
333>>> a ** b
334Decimal("NaN")
335\end{verbatim}
336
337You can combine \class{Decimal} instances with integers, but not with
338floating-point numbers:
339
340\begin{verbatim}
341>>> a + 4
342Decimal("39.72")
343>>> a + 4.5
344Traceback (most recent call last):
345 ...
346TypeError: You can interact Decimal only with int, long or Decimal data types.
347>>>
348\end{verbatim}
349
350\class{Decimal} numbers can be used with the \module{math} and
351\module{cmath} modules, though you'll get back a regular
352floating-point number and not a \class{Decimal}. Instances also have a \method{sqrt()} method:
353
354\begin{verbatim}
355>>> import math, cmath
356>>> d = decimal.Decimal('123456789012.345')
357>>> math.sqrt(d)
358351364.18288201344
359>>> cmath.sqrt(-d)
360351364.18288201344j
361>>> d.sqrt()
362Decimal(``351364.1828820134592177245001'')
363\end{verbatim}
364
365
366\subsection{The \class{Context} type}
367
368Instances of the \class{Context} class encapsulate several settings for
369decimal operations:
370
371\begin{itemize}
372 \item \member{prec} is the precision, the number of decimal places.
373 \item \member{rounding} specifies the rounding mode. The \module{decimal}
374 module has constants for the various possibilities:
375 \constant{ROUND_DOWN}, \constant{ROUND_CEILING}, \constant{ROUND_HALF_EVEN}, and various others.
376 \item \member{trap_enablers} is a dictionary specifying what happens on
377encountering certain error conditions: either an exception is raised or
378a value is returned. Some examples of error conditions are
379division by zero, loss of precision, and overflow.
380\end{itemize}
381
382There's a thread-local default context available by calling
383\function{getcontext()}; you can change the properties of this context
384to alter the default precision, rounding, or trap handling.
385
386\begin{verbatim}
387>>> decimal.getcontext().prec
38828
389>>> decimal.Decimal(1) / decimal.Decimal(7)
390Decimal(``0.1428571428571428571428571429'')
391>>> decimal.getcontext().prec = 9
392>>> decimal.Decimal(1) / decimal.Decimal(7)
393Decimal(``0.142857143'')
394\end{verbatim}
395
396The default action for error conditions is to return a special value
397such as infinity or not-a-number, but you can request that exceptions
398be raised:
399
400\begin{verbatim}
401>>> decimal.Decimal(1) / decimal.Decimal(0)
402Decimal(``Infinity'')
403>>> decimal.getcontext().trap_enablers[decimal.DivisionByZero] = True
404>>> decimal.Decimal(1) / decimal.Decimal(0)
405Traceback (most recent call last):
406 ...
407decimal.DivisionByZero: x / 0
408>>>
409\end{verbatim}
410
411The \class{Context} instance also has various methods for formatting
412numbers such as \method{to_eng_string()} and \method{to_sci_string()}.
413
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000414
415\begin{seealso}
416\seepep{327}{Decimal Data Type}{Written by Facundo Batista and implemented
Andrew M. Kuchlingc8f8a812004-07-04 01:26:42 +0000417 by Facundo Batista, Eric Price, Raymond Hettinger, Aahz, and Tim Peters.}
418
419\seeurl{http://research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html}
420{A more detailed overview of the IEEE-754 representation.}
421
422\seeurl{http://www.lahey.com/float.htm}
423{The article uses Fortran code to illustrate many of the problems
424that floating-point inaccuracy can cause.}
425
426\seeurl{http://www2.hursley.ibm.com/decimal/}
427{A description of a decimal-based representation. This representation
428is being proposed as a standard, and underlies the new Python decimal
429type. Much of this material was written by Mike Cowlishaw, designer of the
430REXX language.}
431
Raymond Hettinger0fff62f2004-07-01 11:52:15 +0000432\end{seealso}
433
434
435%======================================================================
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000436\section{Other Language Changes}
437
438Here are all of the changes that Python 2.4 makes to the core Python
439language.
440
441\begin{itemize}
Raymond Hettingerd4462302003-11-26 17:52:45 +0000442
Raymond Hettinger31017ae2004-03-04 08:25:44 +0000443\item The \method{dict.update()} method now accepts the same
444argument forms as the \class{dict} constructor. This includes any
445mapping, any iterable of key/value pairs, and/or keyword arguments.
446
Raymond Hettingerd4462302003-11-26 17:52:45 +0000447\item The string methods, \method{ljust()}, \method{rjust()}, and
Andrew M. Kuchling67087562003-11-26 18:03:48 +0000448\method{center()} now take an optional argument for specifying a
Raymond Hettingerd4462302003-11-26 17:52:45 +0000449fill character other than a space.
450
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000451\item Strings also gained an \method{rsplit()} method that
Raymond Hettingered54d912003-12-31 01:59:18 +0000452works like the \method{split()} method but splits from the end of
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000453the string.
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000454
455\begin{verbatim}
Raymond Hettinger7a6d2972004-02-13 19:00:07 +0000456>>> 'www.python.org'.split('.', 1)
457['www', 'python.org']
458'www.python.org'.rsplit('.', 1)
459['www.python', 'org']
460\end{verbatim}
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000461
Andrew M. Kuchling2fb4d512003-10-21 12:31:16 +0000462\item The \method{sort()} method of lists gained three keyword
463arguments, \var{cmp}, \var{key}, and \var{reverse}. These arguments
464make some common usages of \method{sort()} simpler. All are optional.
465
466\var{cmp} is the same as the previous single argument to
467\method{sort()}; if provided, the value should be a comparison
468function that takes two arguments and returns -1, 0, or +1 depending
469on how the arguments compare.
470
471\var{key} should be a single-argument function that takes a list
472element and returns a comparison key for the element. The list is
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000473then sorted using the comparison keys. The following example sorts a
474list case-insensitively:
Andrew M. Kuchling2fb4d512003-10-21 12:31:16 +0000475
476\begin{verbatim}
477>>> L = ['A', 'b', 'c', 'D']
478>>> L.sort() # Case-sensitive sort
479>>> L
480['A', 'D', 'b', 'c']
481>>> L.sort(key=lambda x: x.lower())
482>>> L
483['A', 'b', 'c', 'D']
484>>> L.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
485>>> L
486['A', 'b', 'c', 'D']
487\end{verbatim}
488
489The last example, which uses the \var{cmp} parameter, is the old way
Raymond Hettingered54d912003-12-31 01:59:18 +0000490to perform a case-insensitive sort. It works but is slower than
Andrew M. Kuchling2fb4d512003-10-21 12:31:16 +0000491using a \var{key} parameter. Using \var{key} results in calling the
492\method{lower()} method once for each element in the list while using
493\var{cmp} will call the method twice for each comparison.
494
Andrew M. Kuchling981a9182003-11-13 21:33:26 +0000495For simple key functions and comparison functions, it is often
496possible to avoid a \keyword{lambda} expression by using an unbound
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000497method instead. For example, the above case-insensitive sort is best
498coded as:
499
500\begin{verbatim}
501>>> L.sort(key=str.lower)
502>>> L
503['A', 'b', 'c', 'D']
504\end{verbatim}
505
Andrew M. Kuchling2fb4d512003-10-21 12:31:16 +0000506The \var{reverse} parameter should have a Boolean value. If the value is
507\constant{True}, the list will be sorted into reverse order. Instead
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000508of \code{L.sort(lambda x,y: cmp(y.score, x.score))}, you can now write:
509\code{L.sort(key = lambda x: x.score, reverse=True)}.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000510
Andrew M. Kuchling981a9182003-11-13 21:33:26 +0000511The results of sorting are now guaranteed to be stable. This means
512that two entries with equal keys will be returned in the same order as
513they were input. For example, you can sort a list of people by name,
514and then sort the list by age, resulting in a list sorted by age where
515people with the same age are in name-sorted order.
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000516
Fred Drake56fcc232004-05-06 02:55:35 +0000517\item There is a new built-in function
518\function{sorted(\var{iterable})} that works like the in-place
519\method{list.sort()} method but has been made suitable for use in
520expressions. The differences are:
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000521 \begin{itemize}
Raymond Hettinger7d1dd042003-11-12 16:42:10 +0000522 \item the input may be any iterable;
523 \item a newly formed copy is sorted, leaving the original intact; and
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000524 \item the expression returns the new sorted copy
525 \end{itemize}
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000526
527\begin{verbatim}
528>>> L = [9,7,8,3,2,4,1,6,5]
Raymond Hettinger64958a12003-12-17 20:43:33 +0000529>>> [10+i for i in sorted(L)] # usable in a list comprehension
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000530[11, 12, 13, 14, 15, 16, 17, 18, 19]
531>>> L = [9,7,8,3,2,4,1,6,5] # original is left unchanged
532[9,7,8,3,2,4,1,6,5]
Raymond Hettingerd4462302003-11-26 17:52:45 +0000533
Raymond Hettinger64958a12003-12-17 20:43:33 +0000534>>> sorted('Monte Python') # any iterable may be an input
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000535[' ', 'M', 'P', 'e', 'h', 'n', 'n', 'o', 'o', 't', 't', 'y']
Raymond Hettingerd4462302003-11-26 17:52:45 +0000536
537>>> # List the contents of a dict sorted by key values
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000538>>> colormap = dict(red=1, blue=2, green=3, black=4, yellow=5)
Raymond Hettinger64958a12003-12-17 20:43:33 +0000539>>> for k, v in sorted(colormap.iteritems()):
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000540... print k, v
541...
542black 4
543blue 2
544green 3
545red 1
546yellow 5
547
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000548\end{verbatim}
549
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000550\item The \function{zip()} built-in function and \function{itertools.izip()}
Andrew M. Kuchling67087562003-11-26 18:03:48 +0000551 now return an empty list instead of raising a \exception{TypeError}
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000552 exception if called with no arguments. This makes them more
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000553 suitable for use with variable length argument lists:
554
555\begin{verbatim}
556>>> def transpose(array):
557... return zip(*array)
558...
559>>> transpose([(1,2,3), (4,5,6)])
560[(1, 4), (2, 5), (3, 6)]
561>>> transpose([])
562[]
563\end{verbatim}
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000564
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000565\end{itemize}
566
567
568%======================================================================
569\subsection{Optimizations}
570
571\begin{itemize}
572
Raymond Hettingerb7d05db2004-03-08 07:25:05 +0000573\item The inner loops for \class{list} and \class{tuple} slicing
Raymond Hettingerade08ea2004-03-18 09:48:12 +0000574 were optimized and now run about one-third faster. The inner
575 loops were also optimized for \class{dict} with performance
576 boosts to \method{keys()}, \method{values()}, \method{items()},
Fred Drake9de0a2b2004-03-20 08:13:32 +0000577\method{iterkeys()}, \method{itervalues()}, and \method{iteritems()}.
Raymond Hettingerb7d05db2004-03-08 07:25:05 +0000578
Raymond Hettinger7a6d2972004-02-13 19:00:07 +0000579\item The machinery for growing and shrinking lists was optimized
Raymond Hettingerab517d22004-02-14 18:34:46 +0000580 for speed and for space efficiency. Small lists (under eight elements)
581 never over-allocate by more than three elements. Large lists do not
Raymond Hettinger7a6d2972004-02-13 19:00:07 +0000582 over-allocate by more than 1/8th. Appending and popping from lists
583 now runs faster due to more efficient code paths and less frequent
584 use of the underlying system realloc(). List comprehensions also
585 benefit. The amount of improvement varies between systems and shows
586 the greatest improvement on systems with poor realloc() implementations.
Raymond Hettinger79b5cf12004-02-17 10:46:32 +0000587 \method{list.extend()} was also optimized and no longer converts its
588 argument into a temporary list prior to extending the base list.
Raymond Hettinger7a6d2972004-02-13 19:00:07 +0000589
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000590\item \function{list()}, \function{tuple()}, \function{map()},
591 \function{filter()}, and \function{zip()} now run several times
592 faster with non-sequence arguments that supply a \method{__len__()}
593 method. Previously, the pre-sizing optimization only applied to
594 sequence arguments.
595
Raymond Hettinger23a0f4e2004-01-05 08:15:20 +0000596\item The methods \method{list.__getitem__()},
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000597 \method{dict.__getitem__()}, and \method{dict.__contains__()} are
598 are now implemented as \class{method_descriptor} objects rather
599 than \class{wrapper_descriptor} objects. This form of optimized
600 access doubles their performance and makes them more suitable for
Raymond Hettinger23a0f4e2004-01-05 08:15:20 +0000601 use as arguments to functionals:
602 \samp{map(mydict.__getitem__, keylist)}.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000603
Fred Draked6d35d92004-06-03 13:31:22 +0000604\item Added a new opcode, \code{LIST_APPEND}, that simplifies
Raymond Hettingerdd80f762004-03-07 07:31:06 +0000605 the generated bytecode for list comprehensions and speeds them up
606 by about a third.
607
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000608\end{itemize}
609
610The net result of the 2.4 optimizations is that Python 2.4 runs the
611pystone benchmark around XX\% faster than Python 2.3 and YY\% faster
612than Python 2.2.
613
614
615%======================================================================
616\section{New, Improved, and Deprecated Modules}
617
618As usual, Python's standard library received a number of enhancements and
619bug fixes. Here's a partial list of the most notable changes, sorted
620alphabetically by module name. Consult the
621\file{Misc/NEWS} file in the source tree for a more
622complete list of changes, or look through the CVS logs for all the
623details.
624
625\begin{itemize}
626
Andrew M. Kuchling69f31eb2003-08-13 23:11:04 +0000627\item The \module{curses} modules now supports the ncurses extension
Fred Draked6d35d92004-06-03 13:31:22 +0000628 \function{use_default_colors()}. On platforms where the terminal
629 supports transparency, this makes it possible to use a transparent
630 background. (Contributed by J\"org Lehmann.)
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000631
Raymond Hettinger0c410272004-01-05 10:13:35 +0000632\item The \module{bisect} module now has an underlying C implementation
633 for improved performance.
634 (Contributed by Dmitry Vasiliev.)
635
Andrew M. Kuchling5303a962004-01-18 15:55:51 +0000636\item The CJKCodecs collections of East Asian codecs, maintained
637by Hye-Shik Chang, was integrated into 2.4.
638The new encodings are:
639
640\begin{itemize}
641 \item Chinese (PRC): gb2312, gbk, gb18030, hz
642 \item Chinese (ROC): big5, cp950
643 \item Japanese: cp932, shift-jis, shift-jisx0213, euc-jp,
644euc-jisx0213, iso-2022-jp, iso-2022-jp-1, iso-2022-jp-2,
645 iso-2022-jp-3, iso-2022-jp-ext
646 \item Korean: cp949, euc-kr, johab, iso-2022-kr
647\end{itemize}
648
Andrew M. Kuchlingfd0e4942004-02-09 13:23:34 +0000649\item There is a new \module{collections} module for
650 various specialized collection datatypes.
651 Currently it contains just one type, \class{deque},
652 a double-ended queue that supports efficiently adding and removing
653 elements from either end.
Raymond Hettinger756b3f32004-01-29 06:37:52 +0000654
655\begin{verbatim}
656>>> from collections import deque
657>>> d = deque('ghi') # make a new deque with three items
658>>> d.append('j') # add a new entry to the right side
659>>> d.appendleft('f') # add a new entry to the left side
660>>> d # show the representation of the deque
661deque(['f', 'g', 'h', 'i', 'j'])
662>>> d.pop() # return and remove the rightmost item
663'j'
664>>> d.popleft() # return and remove the leftmost item
665'f'
666>>> list(d) # list the contents of the deque
667['g', 'h', 'i']
668>>> 'h' in d # search the deque
669True
670\end{verbatim}
671
Andrew M. Kuchlingfd0e4942004-02-09 13:23:34 +0000672Several modules now take advantage of \class{collections.deque} for
Raymond Hettinger756b3f32004-01-29 06:37:52 +0000673improved performance: \module{Queue}, \module{mutex}, \module{shlex}
674\module{threading}, and \module{pydoc}.
Andrew M. Kuchling5303a962004-01-18 15:55:51 +0000675
Fred Drake9f15b5c2004-05-18 04:30:00 +0000676\item The \module{ConfigParser} classes have been enhanced slightly.
677 The \method{read()} method now returns a list of the files that
678 were successfully parsed, and the \method{set()} method raises
679 \exception{TypeError} if passed a \var{value} argument that isn't a
680 string.
681
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000682\item The \module{heapq} module has been converted to C. The resulting
Andrew M. Kuchlingfd0e4942004-02-09 13:23:34 +0000683 tenfold improvement in speed makes the module suitable for handling
Raymond Hettinger33ecffb2004-06-10 05:03:17 +0000684 high volumes of data. In addition, the module has two new functions
685 \function{nlargest()} and \function{nsmallest()} that use heaps to
686 find the largest or smallest n values in a dataset without the
687 expense of a full sort.
Andrew M. Kuchling1a420252003-11-08 15:58:49 +0000688
Andrew M. Kuchlingdff9dbd2003-11-20 22:22:19 +0000689\item The \module{imaplib} module now supports IMAP's THREAD command.
690(Contributed by Yves Dionne.)
691
Andrew M. Kuchlingad809552003-12-06 23:19:23 +0000692\item The \module{itertools} module gained a
693 \function{groupby(\var{iterable}\optional{, \var{func}})} function,
694 inspired by the GROUP BY clause from SQL.
695 \var{iterable} returns a succession of elements, and the optional
696 \var{func} is a function that takes an element and returns a key
697 value; if omitted, the key is simply the element itself.
698 \function{groupby()} then groups the elements into subsequences
699 which have matching values of the key, and returns a series of 2-tuples
700 containing the key value and an iterator over the subsequence.
701
702Here's an example. The \var{key} function simply returns whether a
703number is even or odd, so the result of \function{groupby()} is to
704return consecutive runs of odd or even numbers.
705
706\begin{verbatim}
707>>> import itertools
708>>> L = [2,4,6, 7,8,9,11, 12, 14]
709>>> for key_val, it in itertools.groupby(L, lambda x: x % 2):
710... print key_val, list(it)
711...
7120 [2, 4, 6]
7131 [7]
7140 [8]
7151 [9, 11]
7160 [12, 14]
717>>>
718\end{verbatim}
719
Raymond Hettingerfeb78c92003-12-12 13:13:47 +0000720Like its SQL counterpart, \function{groupby()} is typically used with
721sorted input. The logic for \function{groupby()} is similar to the
722\UNIX{} \code{uniq} filter which makes it handy for eliminating,
723counting, or identifying duplicate elements:
724
725\begin{verbatim}
726>>> word = 'abracadabra'
Raymond Hettingered54d912003-12-31 01:59:18 +0000727>>> letters = sorted(word) # Turn string into a sorted list of letters
Raymond Hettinger64958a12003-12-17 20:43:33 +0000728>>> letters
Andrew M. Kuchling4612bc52003-12-16 20:59:37 +0000729['a', 'a', 'a', 'a', 'a', 'b', 'b', 'c', 'd', 'r', 'r']
Raymond Hettingered54d912003-12-31 01:59:18 +0000730>>> [k for k, g in groupby(letters)] # List unique letters
Raymond Hettingerfeb78c92003-12-12 13:13:47 +0000731['a', 'b', 'c', 'd', 'r']
Raymond Hettingered54d912003-12-31 01:59:18 +0000732>>> [(k, len(list(g))) for k, g in groupby(letters)] # Count letter occurences
Raymond Hettingerfeb78c92003-12-12 13:13:47 +0000733[('a', 5), ('b', 2), ('c', 1), ('d', 1), ('r', 2)]
Raymond Hettingered54d912003-12-31 01:59:18 +0000734>>> [k for k, g in groupby(letters) if len(list(g)) > 1] # List duplicated letters
Raymond Hettingerfeb78c92003-12-12 13:13:47 +0000735['a', 'b', 'r']
736\end{verbatim}
737
Raymond Hettingered54d912003-12-31 01:59:18 +0000738\item \module{itertools} also gained a function named
739\function{tee(\var{iterator}, \var{N})} that returns \var{N} independent
740iterators that replicate \var{iterator}. If \var{N} is omitted, the
741default is 2.
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000742
743\begin{verbatim}
744>>> L = [1,2,3]
745>>> i1, i2 = itertools.tee(L)
746>>> i1,i2
747(<itertools.tee object at 0x402c2080>, <itertools.tee object at 0x402c2090>)
Raymond Hettingered54d912003-12-31 01:59:18 +0000748>>> list(i1) # Run the first iterator to exhaustion
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000749[1, 2, 3]
Raymond Hettingered54d912003-12-31 01:59:18 +0000750>>> list(i2) # Run the second iterator to exhaustion
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000751[1, 2, 3]
752>\end{verbatim}
753
754Note that \function{tee()} has to keep copies of the values returned
Raymond Hettingered54d912003-12-31 01:59:18 +0000755by the iterator; in the worst case, it may need to keep all of them.
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000756This should therefore be used carefully if the leading iterator
Raymond Hettingered54d912003-12-31 01:59:18 +0000757can run far ahead of the trailing iterator in a long stream of inputs.
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000758If the separation is large, then it becomes preferable to use
Raymond Hettingered54d912003-12-31 01:59:18 +0000759\function{list()} instead. When the iterators track closely with one
760another, \function{tee()} is ideal. Possible applications include
761bookmarking, windowing, or lookahead iterators.
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000762
Andrew M. Kuchlingdff9dbd2003-11-20 22:22:19 +0000763\item A new \function{getsid()} function was added to the
764\module{posix} module that underlies the \module{os} module.
765(Contributed by J. Raynor.)
766
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000767\item The \module{operator} module gained two new functions,
768\function{attrgetter(\var{attr})} and \function{itemgetter(\var{index})}.
769Both functions return callables that take a single argument and return
Raymond Hettingered54d912003-12-31 01:59:18 +0000770the corresponding attribute or item; these callables make excellent
771data extractors when used with \function{map()} or \function{sorted()}.
772For example:
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000773
774\begin{verbatim}
Raymond Hettingered54d912003-12-31 01:59:18 +0000775>>> L = [('c', 2), ('d', 1), ('a', 4), ('b', 3)]
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000776>>> map(operator.itemgetter(0), L)
777['c', 'd', 'a', 'b']
778>>> map(operator.itemgetter(1), L)
Raymond Hettingered54d912003-12-31 01:59:18 +0000779[2, 1, 4, 3]
780>>> sorted(L, key=operator.itemgetter(1)) # Sort list by second tuple item
781[('d', 1), ('c', 2), ('b', 3), ('a', 4)]
Andrew M. Kuchling35f2b052003-12-18 13:28:13 +0000782\end{verbatim}
783
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000784\item The \module{random} module has a new method called \method{getrandbits(N)}
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000785 which returns an N-bit long integer. This method supports the existing
786 \method{randrange()} method, making it possible to efficiently generate
Andrew M. Kuchling44a31e12004-01-01 18:33:34 +0000787 arbitrarily large random numbers.
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000788
789\item The regular expression language accepted by the \module{re} module
790 was extended with simple conditional expressions, written as
791 \code{(?(\var{group})\var{A}|\var{B})}. \var{group} is either a
792 numeric group ID or a group name defined with \code{(?P<group>...)}
793 earlier in the expression. If the specified group matched, the
794 regular expression pattern \var{A} will be tested against the string; if
795 the group didn't match, the pattern \var{B} will be used instead.
Raymond Hettinger874ebd52004-05-31 03:15:02 +0000796
797\item The \module{weakref} module now supports a wider variety of objects
798 including Python functions, class instances, sets, frozensets, deques,
799 arrays, files, sockets, and regular expression pattern objects.
Andrew M. Kuchling69f31eb2003-08-13 23:11:04 +0000800
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000801\end{itemize}
802
803
804%======================================================================
805% whole new modules get described in \subsections here
806
Martin v. Löwis2a6ba902004-05-31 18:22:40 +0000807\subsection{cookielib}
808
809The \module{cookielib} library supports client-side handling for HTTP
810cookies, just as the \module{Cookie} provides server-side cookie
811support in CGI scripts. This library manages cookies in a way similar
812to web browsers. Cookies are stored in cookie jars; the library
813transparently stores cookies offered by the web server in the cookie
814jar, and fetches the cookie from the jar when connecting to the
815server. Similar to web browsers, policy objects control whether
816cookies are accepted or not.
817
818In order to store cookies across sessions, two implementations of
819cookie jars are provided: one that stores cookies in the Netscape
820format, so applications can use the Mozilla or Lynx cookie jars, and
821one that stores cookies in the same format as the Perl libwww libary.
822
823\module{urllib2} has been changed to interact with \module{cookielib}:
824\class{HTTPCookieProcessor} manages a cookie jar that is used when
825accessing URLs.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000826
827% ======================================================================
828\section{Build and C API Changes}
829
830Changes to Python's build process and to the C API include:
831
832\begin{itemize}
833
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000834 \item Three new convenience macros were added for common return
835 values from extension functions: \csimplemacro{Py_RETURN_NONE},
836 \csimplemacro{Py_RETURN_TRUE}, and \csimplemacro{Py_RETURN_FALSE}.
837
Fred Drakece3caf22004-02-12 18:13:12 +0000838 \item A new function, \cfunction{PyTuple_Pack(\var{N}, \var{obj1},
839 \var{obj2}, ..., \var{objN})}, constructs tuples from a variable
840 length argument list of Python objects.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000841
Fred Drakece3caf22004-02-12 18:13:12 +0000842 \item A new function, \cfunction{PyDict_Contains(\var{d}, \var{k})},
843 implements fast dictionary lookups without masking exceptions raised
844 during the look-up process.
Raymond Hettingerd4462302003-11-26 17:52:45 +0000845
Fred Drakece3caf22004-02-12 18:13:12 +0000846 \item A new method flag, \constant{METH_COEXISTS}, allows a function
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000847 defined in slots to co-exist with a PyCFunction having the same name.
848 This can halve the access to time to a method such as
849 \method{set.__contains__()}
850
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000851\end{itemize}
852
853
854%======================================================================
855\subsection{Port-Specific Changes}
856
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000857\begin{itemize}
858
859\item The Windows port now builds under MSVC++ 7.1 as well as version 6.
860
861\end{itemize}
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000862
863
864%======================================================================
865\section{Other Changes and Fixes \label{section-other}}
866
867As usual, there were a bunch of other improvements and bugfixes
868scattered throughout the source tree. A search through the CVS change
869logs finds there were XXX patches applied and YYY bugs fixed between
870Python 2.3 and 2.4. Both figures are likely to be underestimates.
871
872Some of the more notable changes are:
873
874\begin{itemize}
875
Raymond Hettinger97ef8de2004-01-05 00:29:57 +0000876\item The \module{timeit} module now automatically disables periodic
877 garbarge collection during the timing loop. This change makes
878 consecutive timings more comparable.
879
880\item The \module{base64} module now has more complete RFC 3548 support
881 for Base64, Base32, and Base16 encoding and decoding, including
882 optional case folding and optional alternative alphabets.
883 (Contributed by Barry Warsaw.)
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000884
885\end{itemize}
886
887
888%======================================================================
889\section{Porting to Python 2.4}
890
891This section lists previously described changes that may require
892changes to your code:
893
894\begin{itemize}
895
Raymond Hettinger607c00f2003-11-12 16:27:50 +0000896\item The \function{zip()} built-in function and \function{itertools.izip()}
897 now return an empty list instead of raising a \exception{TypeError}
898 exception if called with no arguments.
Andrew M. Kuchling6aedcfc2003-10-21 12:48:23 +0000899
900\item \function{dircache.listdir()} now passes exceptions to the caller
901 instead of returning empty lists.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000902
Fred Drake56fcc232004-05-06 02:55:35 +0000903\item \function{LexicalHandler.startDTD()} used to receive public and
904 system ID in the wrong order. This has been corrected; applications
905 relying on the wrong order need to be fixed.
Martin v. Löwis456ab1d2004-05-06 01:54:36 +0000906
Michael W. Hudson3151e182004-06-03 13:36:42 +0000907\item \function{fcntl.ioctl} now warns if the mutate arg is omitted
Guido van Rossum6dfed6c2004-06-03 13:56:05 +0000908 and relevant.
Martin v. Löwis77ca6c42004-06-03 12:47:26 +0000909
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000910\end{itemize}
911
912
913%======================================================================
914\section{Acknowledgements \label{acks}}
915
916The author would like to thank the following people for offering
917suggestions, corrections and assistance with various drafts of this
Andrew M. Kuchling981a9182003-11-13 21:33:26 +0000918article: Raymond Hettinger.
Fred Drakeed0fa3d2003-07-30 19:14:09 +0000919
920\end{document}