blob: 941f4aab74944ccf05317b6bd44e17236e87635c [file] [log] [blame]
Fred Drake03e10312002-03-26 19:17:43 +00001\documentclass{howto}
Fred Drake693aea22003-02-07 14:52:18 +00002\usepackage{distutils}
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00003% $Id$
4
5\title{What's New in Python 2.3}
Andrew M. Kuchlingd97b01c2003-01-08 02:09:40 +00006\release{0.08}
Fred Drakeaac8c582003-01-17 22:50:10 +00007\author{A.M.\ Kuchling}
Andrew M. Kuchlingbc5e3cc2002-11-05 00:26:33 +00008\authoraddress{\email{amk@amk.ca}}
Fred Drake03e10312002-03-26 19:17:43 +00009
10\begin{document}
11\maketitle
12\tableofcontents
13
Andrew M. Kuchlingc61ec522002-08-04 01:20:05 +000014% MacOS framework-related changes (section of its own, probably)
Andrew M. Kuchlingf70a0a82002-06-10 13:22:46 +000015
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +000016%\section{Introduction \label{intro}}
17
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +000018{\large This article is a draft, and is currently up to date for
19Python 2.3alpha1. Please send any additions, comments or errata to
20the author.}
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +000021
22This article explains the new features in Python 2.3. The tentative
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +000023release date of Python 2.3 is currently scheduled for mid-2003.
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +000024
25This article doesn't attempt to provide a complete specification of
26the new features, but instead provides a convenient overview. For
27full details, you should refer to the documentation for Python 2.3,
Fred Drake693aea22003-02-07 14:52:18 +000028such as the \citetitle[../lib/lib.html]{Python Library Reference} and
29the \citetitle[../ref/ref.html]{Python Reference Manual}. If you want
30to understand the complete implementation and design rationale for a
31change, refer to the PEP for a particular new feature.
Fred Drake03e10312002-03-26 19:17:43 +000032
33
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +000034%======================================================================
Andrew M. Kuchlingbc465102002-08-20 01:34:06 +000035\section{PEP 218: A Standard Set Datatype}
36
37The new \module{sets} module contains an implementation of a set
38datatype. The \class{Set} class is for mutable sets, sets that can
39have members added and removed. The \class{ImmutableSet} class is for
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +000040sets that can't be modified, and instances of \class{ImmutableSet} can
41therefore be used as dictionary keys. Sets are built on top of
42dictionaries, so the elements within a set must be hashable.
Andrew M. Kuchlingbc465102002-08-20 01:34:06 +000043
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +000044Here's a simple example:
Andrew M. Kuchlingbc465102002-08-20 01:34:06 +000045
46\begin{verbatim}
47>>> import sets
48>>> S = sets.Set([1,2,3])
49>>> S
50Set([1, 2, 3])
51>>> 1 in S
52True
53>>> 0 in S
54False
55>>> S.add(5)
56>>> S.remove(3)
57>>> S
58Set([1, 2, 5])
Fred Drake5c4cf152002-11-13 14:59:06 +000059>>>
Andrew M. Kuchlingbc465102002-08-20 01:34:06 +000060\end{verbatim}
61
62The union and intersection of sets can be computed with the
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +000063\method{union()} and \method{intersection()} methods or
64alternatively using the bitwise operators \code{\&} and \code{|}.
Andrew M. Kuchlingbc465102002-08-20 01:34:06 +000065Mutable sets also have in-place versions of these methods,
66\method{union_update()} and \method{intersection_update()}.
67
68\begin{verbatim}
69>>> S1 = sets.Set([1,2,3])
70>>> S2 = sets.Set([4,5,6])
71>>> S1.union(S2)
72Set([1, 2, 3, 4, 5, 6])
73>>> S1 | S2 # Alternative notation
74Set([1, 2, 3, 4, 5, 6])
Fred Drake5c4cf152002-11-13 14:59:06 +000075>>> S1.intersection(S2)
Andrew M. Kuchlingbc465102002-08-20 01:34:06 +000076Set([])
77>>> S1 & S2 # Alternative notation
78Set([])
79>>> S1.union_update(S2)
Andrew M. Kuchlingbc465102002-08-20 01:34:06 +000080>>> S1
81Set([1, 2, 3, 4, 5, 6])
Fred Drake5c4cf152002-11-13 14:59:06 +000082>>>
Andrew M. Kuchlingbc465102002-08-20 01:34:06 +000083\end{verbatim}
84
85It's also possible to take the symmetric difference of two sets. This
86is the set of all elements in the union that aren't in the
87intersection. An alternative way of expressing the symmetric
88difference is that it contains all elements that are in exactly one
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +000089set. Again, there's an alternative notation (\code{\^}), and an
90in-place version with the ungainly name
Andrew M. Kuchlingbc465102002-08-20 01:34:06 +000091\method{symmetric_difference_update()}.
92
93\begin{verbatim}
94>>> S1 = sets.Set([1,2,3,4])
95>>> S2 = sets.Set([3,4,5,6])
96>>> S1.symmetric_difference(S2)
97Set([1, 2, 5, 6])
98>>> S1 ^ S2
99Set([1, 2, 5, 6])
100>>>
101\end{verbatim}
102
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000103There are also \method{issubset()} and \method{issuperset()} methods
Andrew M. Kuchlingbc465102002-08-20 01:34:06 +0000104for checking whether one set is a strict subset or superset of
105another:
106
107\begin{verbatim}
108>>> S1 = sets.Set([1,2,3])
109>>> S2 = sets.Set([2,3])
110>>> S2.issubset(S1)
111True
112>>> S1.issubset(S2)
113False
114>>> S1.issuperset(S2)
115True
116>>>
117\end{verbatim}
118
119
120\begin{seealso}
121
122\seepep{218}{Adding a Built-In Set Object Type}{PEP written by Greg V. Wilson.
123Implemented by Greg V. Wilson, Alex Martelli, and GvR.}
124
125\end{seealso}
126
127
128
129%======================================================================
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000130\section{PEP 255: Simple Generators\label{section-generators}}
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000131
132In Python 2.2, generators were added as an optional feature, to be
133enabled by a \code{from __future__ import generators} directive. In
1342.3 generators no longer need to be specially enabled, and are now
135always present; this means that \keyword{yield} is now always a
136keyword. The rest of this section is a copy of the description of
137generators from the ``What's New in Python 2.2'' document; if you read
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000138it back when Python 2.2 came out, you can skip the rest of this section.
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000139
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000140You're doubtless familiar with how function calls work in Python or C.
141When you call a function, it gets a private namespace where its local
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000142variables are created. When the function reaches a \keyword{return}
143statement, the local variables are destroyed and the resulting value
144is returned to the caller. A later call to the same function will get
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000145a fresh new set of local variables. But, what if the local variables
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000146weren't thrown away on exiting a function? What if you could later
147resume the function where it left off? This is what generators
148provide; they can be thought of as resumable functions.
149
150Here's the simplest example of a generator function:
151
152\begin{verbatim}
153def generate_ints(N):
154 for i in range(N):
155 yield i
156\end{verbatim}
157
158A new keyword, \keyword{yield}, was introduced for generators. Any
159function containing a \keyword{yield} statement is a generator
160function; this is detected by Python's bytecode compiler which
Fred Drake5c4cf152002-11-13 14:59:06 +0000161compiles the function specially as a result.
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000162
163When you call a generator function, it doesn't return a single value;
164instead it returns a generator object that supports the iterator
165protocol. On executing the \keyword{yield} statement, the generator
166outputs the value of \code{i}, similar to a \keyword{return}
167statement. The big difference between \keyword{yield} and a
168\keyword{return} statement is that on reaching a \keyword{yield} the
169generator's state of execution is suspended and local variables are
170preserved. On the next call to the generator's \code{.next()} method,
171the function will resume executing immediately after the
172\keyword{yield} statement. (For complicated reasons, the
173\keyword{yield} statement isn't allowed inside the \keyword{try} block
Fred Drakeaac8c582003-01-17 22:50:10 +0000174of a \keyword{try}...\keyword{finally} statement; read \pep{255} for a full
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000175explanation of the interaction between \keyword{yield} and
176exceptions.)
177
Fred Drakeaac8c582003-01-17 22:50:10 +0000178Here's a sample usage of the \function{generate_ints()} generator:
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000179
180\begin{verbatim}
181>>> gen = generate_ints(3)
182>>> gen
183<generator object at 0x8117f90>
184>>> gen.next()
1850
186>>> gen.next()
1871
188>>> gen.next()
1892
190>>> gen.next()
191Traceback (most recent call last):
Andrew M. Kuchling9f6e1042002-06-17 13:40:04 +0000192 File "stdin", line 1, in ?
193 File "stdin", line 2, in generate_ints
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000194StopIteration
195\end{verbatim}
196
197You could equally write \code{for i in generate_ints(5)}, or
198\code{a,b,c = generate_ints(3)}.
199
200Inside a generator function, the \keyword{return} statement can only
201be used without a value, and signals the end of the procession of
202values; afterwards the generator cannot return any further values.
203\keyword{return} with a value, such as \code{return 5}, is a syntax
204error inside a generator function. The end of the generator's results
205can also be indicated by raising \exception{StopIteration} manually,
206or by just letting the flow of execution fall off the bottom of the
207function.
208
209You could achieve the effect of generators manually by writing your
210own class and storing all the local variables of the generator as
211instance variables. For example, returning a list of integers could
212be done by setting \code{self.count} to 0, and having the
213\method{next()} method increment \code{self.count} and return it.
214However, for a moderately complicated generator, writing a
215corresponding class would be much messier.
216\file{Lib/test/test_generators.py} contains a number of more
217interesting examples. The simplest one implements an in-order
218traversal of a tree using generators recursively.
219
220\begin{verbatim}
221# A recursive generator that generates Tree leaves in in-order.
222def inorder(t):
223 if t:
224 for x in inorder(t.left):
225 yield x
226 yield t.label
227 for x in inorder(t.right):
228 yield x
229\end{verbatim}
230
231Two other examples in \file{Lib/test/test_generators.py} produce
232solutions for the N-Queens problem (placing $N$ queens on an $NxN$
233chess board so that no queen threatens another) and the Knight's Tour
234(a route that takes a knight to every square of an $NxN$ chessboard
Fred Drake5c4cf152002-11-13 14:59:06 +0000235without visiting any square twice).
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000236
237The idea of generators comes from other programming languages,
238especially Icon (\url{http://www.cs.arizona.edu/icon/}), where the
239idea of generators is central. In Icon, every
240expression and function call behaves like a generator. One example
241from ``An Overview of the Icon Programming Language'' at
242\url{http://www.cs.arizona.edu/icon/docs/ipd266.htm} gives an idea of
243what this looks like:
244
245\begin{verbatim}
246sentence := "Store it in the neighboring harbor"
247if (i := find("or", sentence)) > 5 then write(i)
248\end{verbatim}
249
250In Icon the \function{find()} function returns the indexes at which the
251substring ``or'' is found: 3, 23, 33. In the \keyword{if} statement,
252\code{i} is first assigned a value of 3, but 3 is less than 5, so the
253comparison fails, and Icon retries it with the second value of 23. 23
254is greater than 5, so the comparison now succeeds, and the code prints
255the value 23 to the screen.
256
257Python doesn't go nearly as far as Icon in adopting generators as a
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000258central concept. Generators are considered part of the core
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000259Python language, but learning or using them isn't compulsory; if they
260don't solve any problems that you have, feel free to ignore them.
261One novel feature of Python's interface as compared to
262Icon's is that a generator's state is represented as a concrete object
263(the iterator) that can be passed around to other functions or stored
264in a data structure.
265
266\begin{seealso}
267
268\seepep{255}{Simple Generators}{Written by Neil Schemenauer, Tim
269Peters, Magnus Lie Hetland. Implemented mostly by Neil Schemenauer
270and Tim Peters, with other fixes from the Python Labs crew.}
271
272\end{seealso}
273
274
275%======================================================================
Fred Drake13090e12002-08-22 16:51:08 +0000276\section{PEP 263: Source Code Encodings \label{section-encodings}}
Andrew M. Kuchling950725f2002-08-06 01:40:48 +0000277
278Python source files can now be declared as being in different
279character set encodings. Encodings are declared by including a
280specially formatted comment in the first or second line of the source
281file. For example, a UTF-8 file can be declared with:
282
283\begin{verbatim}
284#!/usr/bin/env python
285# -*- coding: UTF-8 -*-
286\end{verbatim}
287
288Without such an encoding declaration, the default encoding used is
Fred Drake5c4cf152002-11-13 14:59:06 +0000289ISO-8859-1, also known as Latin1.
Andrew M. Kuchling950725f2002-08-06 01:40:48 +0000290
291The encoding declaration only affects Unicode string literals; the
292text in the source code will be converted to Unicode using the
293specified encoding. Note that Python identifiers are still restricted
294to ASCII characters, so you can't have variable names that use
295characters outside of the usual alphanumerics.
296
297\begin{seealso}
298
299\seepep{263}{Defining Python Source Code Encodings}{Written by
Martin v. Löwisbd5e38d2002-10-07 18:52:29 +0000300Marc-Andr\'e Lemburg and Martin von L\"owis; implemented by SUZUKI
301Hisao and Martin von L\"owis.}
Andrew M. Kuchling950725f2002-08-06 01:40:48 +0000302
303\end{seealso}
304
305
306%======================================================================
Martin v. Löwisbd5e38d2002-10-07 18:52:29 +0000307\section{PEP 277: Unicode file name support for Windows NT}
Andrew M. Kuchling0f345562002-10-04 22:34:11 +0000308
Martin v. Löwisbd5e38d2002-10-07 18:52:29 +0000309On Windows NT, 2000, and XP, the system stores file names as Unicode
Andrew M. Kuchling0a6fa962002-10-09 12:11:10 +0000310strings. Traditionally, Python has represented file names as byte
311strings, which is inadequate because it renders some file names
Martin v. Löwisbd5e38d2002-10-07 18:52:29 +0000312inaccessible.
313
Andrew M. Kuchling0a6fa962002-10-09 12:11:10 +0000314Python now allows using arbitrary Unicode strings (within the
315limitations of the file system) for all functions that expect file
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000316names, most notably the \function{open()} built-in function. If a Unicode
317string is passed to \function{os.listdir()}, Python now returns a list
Andrew M. Kuchling0a6fa962002-10-09 12:11:10 +0000318of Unicode strings. A new function, \function{os.getcwdu()}, returns
319the current directory as a Unicode string.
Martin v. Löwisbd5e38d2002-10-07 18:52:29 +0000320
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000321Byte strings still work as file names, and on Windows Python will
322transparently convert them to Unicode using the \code{mbcs} encoding.
Martin v. Löwisbd5e38d2002-10-07 18:52:29 +0000323
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000324Other systems also allow Unicode strings as file names but convert
325them to byte strings before passing them to the system, which can
326cause a \exception{UnicodeError} to be raised. Applications can test
327whether arbitrary Unicode strings are supported as file names by
Andrew M. Kuchlingb9ba4e62003-02-03 15:16:15 +0000328checking \member{os.path.supports_unicode_filenames}, a Boolean value.
Martin v. Löwisbd5e38d2002-10-07 18:52:29 +0000329
330\begin{seealso}
331
332\seepep{277}{Unicode file name support for Windows NT}{Written by Neil
333Hodgson; implemented by Neil Hodgson, Martin von L\"owis, and Mark
334Hammond.}
335
336\end{seealso}
Andrew M. Kuchling0f345562002-10-04 22:34:11 +0000337
338
339%======================================================================
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000340\section{PEP 278: Universal Newline Support}
341
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000342The three major operating systems used today are Microsoft Windows,
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000343Apple's Macintosh OS, and the various \UNIX\ derivatives. A minor
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000344irritation is that these three platforms all use different characters
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000345to mark the ends of lines in text files. \UNIX\ uses the linefeed
346(ASCII character 10), while MacOS uses the carriage return (ASCII
347character 13), and Windows uses a two-character sequence containing a
348carriage return plus a newline.
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000349
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000350Python's file objects can now support end of line conventions other
351than the one followed by the platform on which Python is running.
Fred Drake5c4cf152002-11-13 14:59:06 +0000352Opening a file with the mode \code{'U'} or \code{'rU'} will open a file
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000353for reading in universal newline mode. All three line ending
Fred Drake5c4cf152002-11-13 14:59:06 +0000354conventions will be translated to a \character{\e n} in the strings
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000355returned by the various file methods such as \method{read()} and
Fred Drake5c4cf152002-11-13 14:59:06 +0000356\method{readline()}.
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000357
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000358Universal newline support is also used when importing modules and when
359executing a file with the \function{execfile()} function. This means
360that Python modules can be shared between all three operating systems
361without needing to convert the line-endings.
362
Fred Drake5c4cf152002-11-13 14:59:06 +0000363This feature can be disabled at compile-time by specifying
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000364\longprogramopt{without-universal-newlines} when running Python's
Fred Drake5c4cf152002-11-13 14:59:06 +0000365\program{configure} script.
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000366
367\begin{seealso}
368
Fred Drake5c4cf152002-11-13 14:59:06 +0000369\seepep{278}{Universal Newline Support}{Written
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000370and implemented by Jack Jansen.}
371
372\end{seealso}
373
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000374
375%======================================================================
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000376\section{PEP 279: The \function{enumerate()} Built-in Function\label{section-enumerate}}
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000377
378A new built-in function, \function{enumerate()}, will make
379certain loops a bit clearer. \code{enumerate(thing)}, where
380\var{thing} is either an iterator or a sequence, returns a iterator
381that will return \code{(0, \var{thing[0]})}, \code{(1,
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000382\var{thing[1]})}, \code{(2, \var{thing[2]})}, and so forth.
383
384Fairly often you'll see code to change every element of a list that
385looks like this:
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000386
387\begin{verbatim}
388for i in range(len(L)):
389 item = L[i]
390 # ... compute some result based on item ...
391 L[i] = result
392\end{verbatim}
393
394This can be rewritten using \function{enumerate()} as:
395
396\begin{verbatim}
397for i, item in enumerate(L):
398 # ... compute some result based on item ...
399 L[i] = result
400\end{verbatim}
401
402
403\begin{seealso}
404
Fred Drake5c4cf152002-11-13 14:59:06 +0000405\seepep{279}{The enumerate() built-in function}{Written
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000406and implemented by Raymond D. Hettinger.}
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000407
408\end{seealso}
409
410
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000411%======================================================================
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +0000412\section{PEP 282: The \module{logging} Package}
413
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000414A standard package for writing logs, \module{logging}, has been added
415to Python 2.3. It provides a powerful and flexible mechanism for
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +0000416components to generate logging output which can then be filtered and
417processed in various ways. A standard configuration file format can
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000418be used to control the logging behavior of a program. Python's
419standard library includes handlers that will write log records to
420standard error or to a file or socket, send them to the system log, or
421even e-mail them to a particular address, and of course it's also
422possible to write your own handler classes.
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +0000423
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000424The \class{Logger} class is the primary class.
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +0000425Most application code will deal with one or more \class{Logger}
426objects, each one used by a particular subsystem of the application.
427Each \class{Logger} is identified by a name, and names are organized
428into a hierarchy using \samp{.} as the component separator. For
429example, you might have \class{Logger} instances named \samp{server},
430\samp{server.auth} and \samp{server.network}. The latter two
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000431instances are below \samp{server} in the hierarchy. This means that
432if you turn up the verbosity for \samp{server} or direct \samp{server}
433messages to a different handler, the changes will also apply to
434records logged to \samp{server.auth} and \samp{server.network}.
435There's also a root \class{Logger} that's the parent of all other
436loggers.
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +0000437
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +0000438For simple uses, the \module{logging} package contains some
439convenience functions that always use the root log:
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +0000440
441\begin{verbatim}
442import logging
443
444logging.debug('Debugging information')
445logging.info('Informational message')
Andrew M. Kuchlingb1e4bf92002-12-03 13:35:17 +0000446logging.warn('Warning:config file %s not found', 'server.conf')
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +0000447logging.error('Error occurred')
448logging.critical('Critical error -- shutting down')
449\end{verbatim}
450
451This produces the following output:
452
453\begin{verbatim}
Andrew M. Kuchlingb1e4bf92002-12-03 13:35:17 +0000454WARN:root:Warning:config file server.conf not found
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +0000455ERROR:root:Error occurred
456CRITICAL:root:Critical error -- shutting down
457\end{verbatim}
458
459In the default configuration, informational and debugging messages are
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000460suppressed and the output is sent to standard error. You can enable
461the display of information and debugging messages by calling the
462\method{setLevel()} method on the root logger.
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +0000463
464Notice the \function{warn()} call's use of string formatting
465operators; all of the functions for logging messages take the
466arguments \code{(\var{msg}, \var{arg1}, \var{arg2}, ...)} and log the
467string resulting from \code{\var{msg} \% (\var{arg1}, \var{arg2},
468...)}.
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +0000469
470There's also an \function{exception()} function that records the most
471recent traceback. Any of the other functions will also record the
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +0000472traceback if you specify a true value for the keyword argument
Fred Drakeaac8c582003-01-17 22:50:10 +0000473\var{exc_info}.
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +0000474
475\begin{verbatim}
476def f():
477 try: 1/0
478 except: logging.exception('Problem recorded')
479
480f()
481\end{verbatim}
482
483This produces the following output:
484
485\begin{verbatim}
486ERROR:root:Problem recorded
487Traceback (most recent call last):
488 File "t.py", line 6, in f
489 1/0
490ZeroDivisionError: integer division or modulo by zero
491\end{verbatim}
492
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +0000493Slightly more advanced programs will use a logger other than the root
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000494logger. The \function{getLogger(\var{name})} function is used to get
495a particular log, creating it if it doesn't exist yet.
Andrew M. Kuchlingb1e4bf92002-12-03 13:35:17 +0000496\function{getLogger(None)} returns the root logger.
497
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +0000498
499\begin{verbatim}
500log = logging.getLogger('server')
501 ...
502log.info('Listening on port %i', port)
503 ...
504log.critical('Disk full')
505 ...
506\end{verbatim}
507
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +0000508Log records are usually propagated up the hierarchy, so a message
509logged to \samp{server.auth} is also seen by \samp{server} and
510\samp{root}, but a handler can prevent this by setting its
Fred Drakeaac8c582003-01-17 22:50:10 +0000511\member{propagate} attribute to \constant{False}.
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +0000512
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000513There are more classes provided by the \module{logging} package that
514can be customized. When a \class{Logger} instance is told to log a
515message, it creates a \class{LogRecord} instance that is sent to any
516number of different \class{Handler} instances. Loggers and handlers
517can also have an attached list of filters, and each filter can cause
518the \class{LogRecord} to be ignored or can modify the record before
519passing it along. \class{LogRecord} instances are converted to text
520for output by a \class{Formatter} class. All of these classes can be
521replaced by your own specially-written classes.
522
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +0000523With all of these features the \module{logging} package should provide
524enough flexibility for even the most complicated applications. This
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000525is only a partial overview of the \module{logging} package, so please
526see the \ulink{package's reference
Fred Drake693aea22003-02-07 14:52:18 +0000527documentation}{../lib/module-logging.html} for all of the details.
528Reading \pep{282} will also be helpful.
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +0000529
530
531\begin{seealso}
532
533\seepep{282}{A Logging System}{Written by Vinay Sajip and Trent Mick;
534implemented by Vinay Sajip.}
535
536\end{seealso}
537
538
539%======================================================================
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000540\section{PEP 285: The \class{bool} Type\label{section-bool}}
541
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000542A Boolean type was added to Python 2.3. Two new constants were added
543to the \module{__builtin__} module, \constant{True} and
Andrew M. Kuchling5a224532003-01-03 16:52:27 +0000544\constant{False}. (\constant{True} and
545\constant{False} constants were added to the built-ins
546in Python 2.2.2, but the 2.2.2 versions simply have integer values of
5471 and 0 and aren't a different type.)
548
549The type object for this new type is named
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000550\class{bool}; the constructor for it takes any Python value and
551converts it to \constant{True} or \constant{False}.
552
553\begin{verbatim}
554>>> bool(1)
555True
556>>> bool(0)
557False
558>>> bool([])
559False
560>>> bool( (1,) )
561True
562\end{verbatim}
563
564Most of the standard library modules and built-in functions have been
565changed to return Booleans.
566
567\begin{verbatim}
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000568>>> obj = []
569>>> hasattr(obj, 'append')
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000570True
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000571>>> isinstance(obj, list)
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000572True
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000573>>> isinstance(obj, tuple)
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000574False
575\end{verbatim}
576
577Python's Booleans were added with the primary goal of making code
578clearer. For example, if you're reading a function and encounter the
Fred Drake5c4cf152002-11-13 14:59:06 +0000579statement \code{return 1}, you might wonder whether the \code{1}
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000580represents a Boolean truth value, an index, or a
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000581coefficient that multiplies some other quantity. If the statement is
582\code{return True}, however, the meaning of the return value is quite
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000583clear.
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000584
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000585Python's Booleans were \emph{not} added for the sake of strict
586type-checking. A very strict language such as Pascal would also
587prevent you performing arithmetic with Booleans, and would require
588that the expression in an \keyword{if} statement always evaluate to a
589Boolean. Python is not this strict, and it never will be, as
590\pep{285} explicitly says. This means you can still use any
591expression in an \keyword{if} statement, even ones that evaluate to a
592list or tuple or some random object, and the Boolean type is a
593subclass of the \class{int} class so that arithmetic using a Boolean
594still works.
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000595
596\begin{verbatim}
597>>> True + 1
5982
599>>> False + 1
6001
601>>> False * 75
6020
603>>> True * 75
60475
605\end{verbatim}
606
607To sum up \constant{True} and \constant{False} in a sentence: they're
608alternative ways to spell the integer values 1 and 0, with the single
609difference that \function{str()} and \function{repr()} return the
Fred Drake5c4cf152002-11-13 14:59:06 +0000610strings \code{'True'} and \code{'False'} instead of \code{'1'} and
611\code{'0'}.
Andrew M. Kuchling3a52ff62002-04-03 22:44:47 +0000612
613\begin{seealso}
614
615\seepep{285}{Adding a bool type}{Written and implemented by GvR.}
616
617\end{seealso}
618
Michael W. Hudson5efaf7e2002-06-11 10:55:12 +0000619
Andrew M. Kuchling65b72822002-09-03 00:53:21 +0000620%======================================================================
621\section{PEP 293: Codec Error Handling Callbacks}
622
Martin v. Löwis20eae692002-10-07 19:01:07 +0000623When encoding a Unicode string into a byte string, unencodable
Andrew M. Kuchling0a6fa962002-10-09 12:11:10 +0000624characters may be encountered. So far, Python has allowed specifying
625the error processing as either ``strict'' (raising
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000626\exception{UnicodeError}), ``ignore'' (skipping the character), or
627``replace'' (using a question mark in the output string), with
628``strict'' being the default behavior. It may be desirable to specify
629alternative processing of such errors, such as inserting an XML
630character reference or HTML entity reference into the converted
631string.
Martin v. Löwis20eae692002-10-07 19:01:07 +0000632
Andrew M. Kuchlingb492fa92002-11-27 19:11:10 +0000633Python now has a flexible framework to add different processing
Andrew M. Kuchling0a6fa962002-10-09 12:11:10 +0000634strategies. New error handlers can be added with
Martin v. Löwis20eae692002-10-07 19:01:07 +0000635\function{codecs.register_error}. Codecs then can access the error
Andrew M. Kuchling0a6fa962002-10-09 12:11:10 +0000636handler with \function{codecs.lookup_error}. An equivalent C API has
637been added for codecs written in C. The error handler gets the
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000638necessary state information such as the string being converted, the
Andrew M. Kuchling0a6fa962002-10-09 12:11:10 +0000639position in the string where the error was detected, and the target
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000640encoding. The handler can then either raise an exception or return a
Andrew M. Kuchling0a6fa962002-10-09 12:11:10 +0000641replacement string.
Martin v. Löwis20eae692002-10-07 19:01:07 +0000642
643Two additional error handlers have been implemented using this
Andrew M. Kuchling0a6fa962002-10-09 12:11:10 +0000644framework: ``backslashreplace'' uses Python backslash quoting to
Andrew M. Kuchlingb492fa92002-11-27 19:11:10 +0000645represent unencodable characters and ``xmlcharrefreplace'' emits
Martin v. Löwis20eae692002-10-07 19:01:07 +0000646XML character references.
Andrew M. Kuchling65b72822002-09-03 00:53:21 +0000647
648\begin{seealso}
649
Fred Drake5c4cf152002-11-13 14:59:06 +0000650\seepep{293}{Codec Error Handling Callbacks}{Written and implemented by
Andrew M. Kuchling0a6fa962002-10-09 12:11:10 +0000651Walter D\"orwald.}
Andrew M. Kuchling65b72822002-09-03 00:53:21 +0000652
653\end{seealso}
654
655
656%======================================================================
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000657\section{PEP 273: Importing Modules from Zip Archives}
658
659The new \module{zipimport} module adds support for importing
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000660modules from a ZIP-format archive. You don't need to import the
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000661module explicitly; it will be automatically imported if a ZIP
662archive's filename is added to \code{sys.path}. For example:
663
664\begin{verbatim}
665amk@nyman:~/src/python$ unzip -l /tmp/example.zip
666Archive: /tmp/example.zip
667 Length Date Time Name
668 -------- ---- ---- ----
669 8467 11-26-02 22:30 jwzthreading.py
670 -------- -------
671 8467 1 file
672amk@nyman:~/src/python$ ./python
673Python 2.3a0 (#1, Dec 30 2002, 19:54:32)
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000674>>> import sys
675>>> sys.path.insert(0, '/tmp/example.zip') # Add .zip file to front of path
676>>> import jwzthreading
677>>> jwzthreading.__file__
678'/tmp/example.zip/jwzthreading.py'
679>>>
680\end{verbatim}
681
682An entry in \code{sys.path} can now be the filename of a ZIP archive.
683The ZIP archive can contain any kind of files, but only files named
Fred Drakeaac8c582003-01-17 22:50:10 +0000684\file{*.py}, \file{*.pyc}, or \file{*.pyo} can be imported. If an
685archive only contains \file{*.py} files, Python will not attempt to
686modify the archive by adding the corresponding \file{*.pyc} file, meaning
687that if a ZIP archive doesn't contain \file{*.pyc} files, importing may be
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000688rather slow.
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000689
690A path within the archive can also be specified to only import from a
691subdirectory; for example, the path \file{/tmp/example.zip/lib/}
692would only import from the \file{lib/} subdirectory within the
693archive.
694
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000695\begin{seealso}
696
697\seepep{273}{Import Modules from Zip Archives}{Written by James C. Ahlstrom,
698who also provided an implementation.
699Python 2.3 follows the specification in \pep{273},
Andrew M. Kuchlingae3bbf52002-12-31 14:03:45 +0000700but uses an implementation written by Just van~Rossum
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000701that uses the import hooks described in \pep{302}.
702See section~\ref{section-pep302} for a description of the new import hooks.
703}
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000704
705\end{seealso}
706
707%======================================================================
Fred Drake693aea22003-02-07 14:52:18 +0000708\section{PEP 301: Package Index and Metadata for
709Distutils\label{section-pep301}}
Andrew M. Kuchling87cebbf2003-01-03 16:24:28 +0000710
Andrew M. Kuchling5a224532003-01-03 16:52:27 +0000711Support for the long-requested Python catalog makes its first
712appearance in 2.3.
713
Fred Drake693aea22003-02-07 14:52:18 +0000714The core component is the new Distutils \command{register} command.
715Running \code{python setup.py register} will collect the metadata
Andrew M. Kuchling5a224532003-01-03 16:52:27 +0000716describing a package, such as its name, version, maintainer,
Fred Drake693aea22003-02-07 14:52:18 +0000717description, \&c., and send it to a central catalog server.
Andrew M. Kuchling5a224532003-01-03 16:52:27 +0000718Currently the catalog can be browsed at
719\url{http://www.amk.ca/cgi-bin/pypi.cgi}, but it will move to
720some hostname in the \code{python.org} domain before the final version
721of 2.3 is released.
722
723To make the catalog a bit more useful, a new optional
Fred Drake693aea22003-02-07 14:52:18 +0000724\var{classifiers} keyword argument has been added to the Distutils
Andrew M. Kuchling5a224532003-01-03 16:52:27 +0000725\function{setup()} function. A list of
Fred Drake693aea22003-02-07 14:52:18 +0000726\ulink{Trove}{http://catb.org/\textasciitilde esr/trove/}-style
727strings can be supplied to help classify the software.
Andrew M. Kuchling5a224532003-01-03 16:52:27 +0000728
Andrew M. Kuchlinga31bb372003-01-27 16:36:34 +0000729Here's an example \file{setup.py} with classifiers, written to be compatible
730with older versions of the Distutils:
Andrew M. Kuchling5a224532003-01-03 16:52:27 +0000731
732\begin{verbatim}
Andrew M. Kuchlinga31bb372003-01-27 16:36:34 +0000733from distutils import core
Fred Drake693aea22003-02-07 14:52:18 +0000734kw = {'name': "Quixote",
Andrew M. Kuchlinga31bb372003-01-27 16:36:34 +0000735 'version': "0.5.1",
736 'description': "A highly Pythonic Web application framework",
Fred Drake693aea22003-02-07 14:52:18 +0000737 # ...
738 }
Andrew M. Kuchlinga31bb372003-01-27 16:36:34 +0000739
Fred Drake693aea22003-02-07 14:52:18 +0000740if ( hasattr(core, 'setup_keywords') and
741 'classifiers' in core.setup_keywords):
742 kw['classifiers'] = \
743 ['Topic :: Internet :: WWW/HTTP :: Dynamic Content',
744 'Environment :: No Input/Output (Daemon)',
745 'Intended Audience :: Developers'],
Andrew M. Kuchlinga31bb372003-01-27 16:36:34 +0000746
Fred Drake693aea22003-02-07 14:52:18 +0000747core.setup(**kw)
Andrew M. Kuchling5a224532003-01-03 16:52:27 +0000748\end{verbatim}
749
750The full list of classifiers can be obtained by running
751\code{python setup.py register --list-classifiers}.
Andrew M. Kuchling87cebbf2003-01-03 16:24:28 +0000752
753\begin{seealso}
754
Fred Drake693aea22003-02-07 14:52:18 +0000755\seepep{301}{Package Index and Metadata for Distutils}{Written and
756implemented by Richard Jones.}
Andrew M. Kuchling87cebbf2003-01-03 16:24:28 +0000757
758\end{seealso}
759
760
761%======================================================================
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000762\section{PEP 302: New Import Hooks \label{section-pep302}}
763
764While it's been possible to write custom import hooks ever since the
765\module{ihooks} module was introduced in Python 1.3, no one has ever
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000766been really happy with it because writing new import hooks is
767difficult and messy. There have been various proposed alternatives
768such as the \module{imputil} and \module{iu} modules, but none of them
769has ever gained much acceptance, and none of them were easily usable
770from \C{} code.
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000771
772\pep{302} borrows ideas from its predecessors, especially from
773Gordon McMillan's \module{iu} module. Three new items
774are added to the \module{sys} module:
775
776\begin{itemize}
Andrew M. Kuchlingd5ac8d02003-01-02 21:33:15 +0000777 \item \code{sys.path_hooks} is a list of callable objects; most
Fred Drakeaac8c582003-01-17 22:50:10 +0000778 often they'll be classes. Each callable takes a string containing a
779 path and either returns an importer object that will handle imports
780 from this path or raises an \exception{ImportError} exception if it
781 can't handle this path.
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000782
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000783 \item \code{sys.path_importer_cache} caches importer objects for
Fred Drakeaac8c582003-01-17 22:50:10 +0000784 each path, so \code{sys.path_hooks} will only need to be traversed
785 once for each path.
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000786
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000787 \item \code{sys.meta_path} is a list of importer objects that will
788 be traversed before \code{sys.path} is checked. This list is
789 initially empty, but user code can add objects to it. Additional
790 built-in and frozen modules can be imported by an object added to
791 this list.
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000792
793\end{itemize}
794
795Importer objects must have a single method,
796\method{find_module(\var{fullname}, \var{path}=None)}. \var{fullname}
797will be a module or package name, e.g. \samp{string} or
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000798\samp{distutils.core}. \method{find_module()} must return a loader object
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000799that has a single method, \method{load_module(\var{fullname})}, that
800creates and returns the corresponding module object.
801
802Pseudo-code for Python's new import logic, therefore, looks something
803like this (simplified a bit; see \pep{302} for the full details):
804
805\begin{verbatim}
806for mp in sys.meta_path:
807 loader = mp(fullname)
808 if loader is not None:
Andrew M. Kuchlingd5ac8d02003-01-02 21:33:15 +0000809 <module> = loader.load_module(fullname)
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000810
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000811for path in sys.path:
812 for hook in sys.path_hooks:
Andrew M. Kuchlingd5ac8d02003-01-02 21:33:15 +0000813 try:
814 importer = hook(path)
815 except ImportError:
816 # ImportError, so try the other path hooks
817 pass
818 else:
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000819 loader = importer.find_module(fullname)
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000820 <module> = loader.load_module(fullname)
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000821
822# Not found!
823raise ImportError
824\end{verbatim}
825
826\begin{seealso}
827
828\seepep{302}{New Import Hooks}{Written by Just van~Rossum and Paul Moore.
Andrew M. Kuchlingae3bbf52002-12-31 14:03:45 +0000829Implemented by Just van~Rossum.
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000830}
831
832\end{seealso}
833
834
835%======================================================================
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000836\section{Extended Slices\label{section-slices}}
Michael W. Hudson5efaf7e2002-06-11 10:55:12 +0000837
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000838Ever since Python 1.4, the slicing syntax has supported an optional
839third ``step'' or ``stride'' argument. For example, these are all
840legal Python syntax: \code{L[1:10:2]}, \code{L[:-1:1]},
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000841\code{L[::-1]}. This was added to Python at the request of
842the developers of Numerical Python, which uses the third argument
843extensively. However, Python's built-in list, tuple, and string
844sequence types have never supported this feature, and you got a
845\exception{TypeError} if you tried it. Michael Hudson contributed a
846patch to fix this shortcoming.
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000847
848For example, you can now easily extract the elements of a list that
849have even indexes:
Fred Drakedf872a22002-07-03 12:02:01 +0000850
851\begin{verbatim}
852>>> L = range(10)
853>>> L[::2]
854[0, 2, 4, 6, 8]
855\end{verbatim}
856
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000857Negative values also work to make a copy of the same list in reverse
858order:
Fred Drakedf872a22002-07-03 12:02:01 +0000859
860\begin{verbatim}
861>>> L[::-1]
862[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
863\end{verbatim}
Andrew M. Kuchling3a52ff62002-04-03 22:44:47 +0000864
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000865This also works for tuples, arrays, and strings:
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000866
867\begin{verbatim}
868>>> s='abcd'
869>>> s[::2]
870'ac'
871>>> s[::-1]
872'dcba'
873\end{verbatim}
874
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000875If you have a mutable sequence such as a list or an array you can
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000876assign to or delete an extended slice, but there are some differences
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000877between assignment to extended and regular slices. Assignment to a
878regular slice can be used to change the length of the sequence:
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000879
880\begin{verbatim}
881>>> a = range(3)
882>>> a
883[0, 1, 2]
884>>> a[1:3] = [4, 5, 6]
885>>> a
886[0, 4, 5, 6]
887\end{verbatim}
888
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000889Extended slices aren't this flexible. When assigning to an extended
890slice the list on the right hand side of the statement must contain
891the same number of items as the slice it is replacing:
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000892
893\begin{verbatim}
894>>> a = range(4)
895>>> a
896[0, 1, 2, 3]
897>>> a[::2]
898[0, 2]
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000899>>> a[::2] = [0, -1]
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000900>>> a
901[0, 1, -1, 3]
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000902>>> a[::2] = [0,1,2]
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000903Traceback (most recent call last):
904 File "<stdin>", line 1, in ?
Raymond Hettingeree1bded2003-01-17 16:20:23 +0000905ValueError: attempt to assign sequence of size 3 to extended slice of size 2
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000906\end{verbatim}
907
908Deletion is more straightforward:
909
910\begin{verbatim}
911>>> a = range(4)
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000912>>> a
913[0, 1, 2, 3]
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000914>>> a[::2]
915[0, 2]
916>>> del a[::2]
917>>> a
918[1, 3]
919\end{verbatim}
920
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000921One can also now pass slice objects to the
922\method{__getitem__} methods of the built-in sequences:
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000923
924\begin{verbatim}
925>>> range(10).__getitem__(slice(0, 5, 2))
926[0, 2, 4]
927\end{verbatim}
928
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000929Or use slice objects directly in subscripts:
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000930
931\begin{verbatim}
932>>> range(10)[slice(0, 5, 2)]
933[0, 2, 4]
934\end{verbatim}
935
Andrew M. Kuchlingb6f79592002-11-29 19:43:45 +0000936To simplify implementing sequences that support extended slicing,
937slice objects now have a method \method{indices(\var{length})} which,
Fred Drakeaac8c582003-01-17 22:50:10 +0000938given the length of a sequence, returns a \code{(\var{start},
939\var{stop}, \var{step})} tuple that can be passed directly to
940\function{range()}.
Andrew M. Kuchlingb6f79592002-11-29 19:43:45 +0000941\method{indices()} handles omitted and out-of-bounds indices in a
942manner consistent with regular slices (and this innocuous phrase hides
943a welter of confusing details!). The method is intended to be used
944like this:
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000945
946\begin{verbatim}
947class FakeSeq:
948 ...
949 def calc_item(self, i):
950 ...
951 def __getitem__(self, item):
952 if isinstance(item, slice):
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000953 indices = item.indices(len(self))
954 return FakeSeq([self.calc_item(i) in range(*indices)])
Fred Drake5c4cf152002-11-13 14:59:06 +0000955 else:
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000956 return self.calc_item(i)
957\end{verbatim}
958
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +0000959From this example you can also see that the built-in \class{slice}
Andrew M. Kuchling90e9a792002-08-15 00:40:21 +0000960object is now the type object for the slice type, and is no longer a
961function. This is consistent with Python 2.2, where \class{int},
962\class{str}, etc., underwent the same change.
963
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000964
Andrew M. Kuchling3a52ff62002-04-03 22:44:47 +0000965%======================================================================
Fred Drakedf872a22002-07-03 12:02:01 +0000966\section{Other Language Changes}
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000967
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000968Here are all of the changes that Python 2.3 makes to the core Python
969language.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000970
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000971\begin{itemize}
972\item The \keyword{yield} statement is now always a keyword, as
973described in section~\ref{section-generators} of this document.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000974
Fred Drake5c4cf152002-11-13 14:59:06 +0000975\item A new built-in function \function{enumerate()}
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000976was added, as described in section~\ref{section-enumerate} of this
977document.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000978
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000979\item Two new constants, \constant{True} and \constant{False} were
980added along with the built-in \class{bool} type, as described in
981section~\ref{section-bool} of this document.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000982
Andrew M. Kuchling495172c2002-11-20 13:50:15 +0000983\item The \function{int()} type constructor will now return a long
984integer instead of raising an \exception{OverflowError} when a string
985or floating-point number is too large to fit into an integer. This
986can lead to the paradoxical result that
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +0000987\code{isinstance(int(\var{expression}), int)} is false, but that seems
988unlikely to cause problems in practice.
Andrew M. Kuchling495172c2002-11-20 13:50:15 +0000989
Fred Drake5c4cf152002-11-13 14:59:06 +0000990\item Built-in types now support the extended slicing syntax,
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000991as described in section~\ref{section-slices} of this document.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000992
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000993\item Dictionaries have a new method, \method{pop(\var{key})}, that
994returns the value corresponding to \var{key} and removes that
995key/value pair from the dictionary. \method{pop()} will raise a
996\exception{KeyError} if the requested key isn't present in the
997dictionary:
998
999\begin{verbatim}
1000>>> d = {1:2}
1001>>> d
1002{1: 2}
1003>>> d.pop(4)
1004Traceback (most recent call last):
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +00001005 File "stdin", line 1, in ?
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +00001006KeyError: 4
1007>>> d.pop(1)
10082
1009>>> d.pop(1)
1010Traceback (most recent call last):
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +00001011 File "stdin", line 1, in ?
Raymond Hettingeree1bded2003-01-17 16:20:23 +00001012KeyError: 'pop(): dictionary is empty'
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +00001013>>> d
1014{}
1015>>>
1016\end{verbatim}
1017
Andrew M. Kuchlingb492fa92002-11-27 19:11:10 +00001018There's also a new class method,
1019\method{dict.fromkeys(\var{iterable}, \var{value})}, that
1020creates a dictionary with keys taken from the supplied iterator
1021\var{iterable} and all values set to \var{value}, defaulting to
1022\code{None}.
1023
1024(Patches contributed by Raymond Hettinger.)
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +00001025
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +00001026Also, the \function{dict()} constructor now accepts keyword arguments to
Raymond Hettinger45bda572002-12-14 20:20:45 +00001027simplify creating small dictionaries:
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001028
1029\begin{verbatim}
1030>>> dict(red=1, blue=2, green=3, black=4)
1031{'blue': 2, 'black': 4, 'green': 3, 'red': 1}
1032\end{verbatim}
1033
Andrew M. Kuchlingae3bbf52002-12-31 14:03:45 +00001034(Contributed by Just van~Rossum.)
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001035
Andrew M. Kuchling7a82b8c2002-11-04 20:17:24 +00001036\item The \keyword{assert} statement no longer checks the \code{__debug__}
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001037flag, so you can no longer disable assertions by assigning to \code{__debug__}.
Fred Drake5c4cf152002-11-13 14:59:06 +00001038Running Python with the \programopt{-O} switch will still generate
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001039code that doesn't execute any assertions.
1040
1041\item Most type objects are now callable, so you can use them
1042to create new objects such as functions, classes, and modules. (This
1043means that the \module{new} module can be deprecated in a future
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001044Python version, because you can now use the type objects available in
1045the \module{types} module.)
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001046% XXX should new.py use PendingDeprecationWarning?
1047For example, you can create a new module object with the following code:
1048
1049\begin{verbatim}
1050>>> import types
1051>>> m = types.ModuleType('abc','docstring')
1052>>> m
1053<module 'abc' (built-in)>
1054>>> m.__doc__
1055'docstring'
1056\end{verbatim}
1057
Fred Drake5c4cf152002-11-13 14:59:06 +00001058\item
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001059A new warning, \exception{PendingDeprecationWarning} was added to
1060indicate features which are in the process of being
1061deprecated. The warning will \emph{not} be printed by default. To
1062check for use of features that will be deprecated in the future,
1063supply \programopt{-Walways::PendingDeprecationWarning::} on the
1064command line or use \function{warnings.filterwarnings()}.
1065
Andrew M. Kuchlingc1dd1742003-01-13 13:59:22 +00001066\item The process of deprecating string-based exceptions, as
1067in \code{raise "Error occurred"}, has begun. Raising a string will
1068now trigger \exception{PendingDeprecationWarning}.
1069
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001070\item Using \code{None} as a variable name will now result in a
1071\exception{SyntaxWarning} warning. In a future version of Python,
1072\code{None} may finally become a keyword.
1073
Andrew M. Kuchlingb60ea3f2002-11-15 14:37:10 +00001074\item The method resolution order used by new-style classes has
1075changed, though you'll only notice the difference if you have a really
1076complicated inheritance hierarchy. (Classic classes are unaffected by
1077this change.) Python 2.2 originally used a topological sort of a
1078class's ancestors, but 2.3 now uses the C3 algorithm as described in
Andrew M. Kuchling6f429c32002-11-19 13:09:00 +00001079the paper \ulink{``A Monotonic Superclass Linearization for
1080Dylan''}{http://www.webcom.com/haahr/dylan/linearization-oopsla96.html}.
Andrew M. Kuchlingc1dd1742003-01-13 13:59:22 +00001081To understand the motivation for this change,
1082read Michele Simionato's article
Fred Drake693aea22003-02-07 14:52:18 +00001083\ulink{``Python 2.3 Method Resolution Order''}
Andrew M. Kuchlingb8a39052003-02-07 20:22:33 +00001084 {http://www.python.org/2.3/mro.html}, or
Andrew M. Kuchlingc1dd1742003-01-13 13:59:22 +00001085read the thread on python-dev starting with the message at
Andrew M. Kuchlingb60ea3f2002-11-15 14:37:10 +00001086\url{http://mail.python.org/pipermail/python-dev/2002-October/029035.html}.
1087Samuele Pedroni first pointed out the problem and also implemented the
1088fix by coding the C3 algorithm.
1089
Andrew M. Kuchlingdcfd8252002-09-13 22:21:42 +00001090\item Python runs multithreaded programs by switching between threads
1091after executing N bytecodes. The default value for N has been
1092increased from 10 to 100 bytecodes, speeding up single-threaded
1093applications by reducing the switching overhead. Some multithreaded
1094applications may suffer slower response time, but that's easily fixed
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001095by setting the limit back to a lower number using
Andrew M. Kuchlingdcfd8252002-09-13 22:21:42 +00001096\function{sys.setcheckinterval(\var{N})}.
1097
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001098\item One minor but far-reaching change is that the names of extension
1099types defined by the modules included with Python now contain the
Fred Drake5c4cf152002-11-13 14:59:06 +00001100module and a \character{.} in front of the type name. For example, in
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001101Python 2.2, if you created a socket and printed its
1102\member{__class__}, you'd get this output:
1103
1104\begin{verbatim}
1105>>> s = socket.socket()
1106>>> s.__class__
1107<type 'socket'>
1108\end{verbatim}
1109
1110In 2.3, you get this:
1111\begin{verbatim}
1112>>> s.__class__
1113<type '_socket.socket'>
1114\end{verbatim}
1115
Michael W. Hudson96bc3b42002-11-26 14:48:23 +00001116\item One of the noted incompatibilities between old- and new-style
1117 classes has been removed: you can now assign to the
1118 \member{__name__} and \member{__bases__} attributes of new-style
1119 classes. There are some restrictions on what can be assigned to
1120 \member{__bases__} along the lines of those relating to assigning to
1121 an instance's \member{__class__} attribute.
1122
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001123\end{itemize}
1124
1125
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +00001126%======================================================================
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001127\subsection{String Changes}
1128
1129\begin{itemize}
1130
Fred Drakeaac8c582003-01-17 22:50:10 +00001131\item The \keyword{in} operator now works differently for strings.
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001132Previously, when evaluating \code{\var{X} in \var{Y}} where \var{X}
1133and \var{Y} are strings, \var{X} could only be a single character.
1134That's now changed; \var{X} can be a string of any length, and
1135\code{\var{X} in \var{Y}} will return \constant{True} if \var{X} is a
1136substring of \var{Y}. If \var{X} is the empty string, the result is
1137always \constant{True}.
1138
1139\begin{verbatim}
1140>>> 'ab' in 'abcd'
1141True
1142>>> 'ad' in 'abcd'
1143False
1144>>> '' in 'abcd'
1145True
1146\end{verbatim}
1147
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001148Note that this doesn't tell you where the substring starts; if you
1149need that information, you must use the \method{find()} method
1150instead.
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001151
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +00001152\item The \method{strip()}, \method{lstrip()}, and \method{rstrip()}
1153string methods now have an optional argument for specifying the
1154characters to strip. The default is still to remove all whitespace
1155characters:
1156
1157\begin{verbatim}
1158>>> ' abc '.strip()
1159'abc'
1160>>> '><><abc<><><>'.strip('<>')
1161'abc'
1162>>> '><><abc<><><>\n'.strip('<>')
1163'abc<><><>\n'
1164>>> u'\u4000\u4001abc\u4000'.strip(u'\u4000')
1165u'\u4001abc'
1166>>>
1167\end{verbatim}
1168
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001169(Suggested by Simon Brunning and implemented by Walter D\"orwald.)
Andrew M. Kuchling346386f2002-07-12 20:24:42 +00001170
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +00001171\item The \method{startswith()} and \method{endswith()}
1172string methods now accept negative numbers for the start and end
1173parameters.
1174
1175\item Another new string method is \method{zfill()}, originally a
1176function in the \module{string} module. \method{zfill()} pads a
1177numeric string with zeros on the left until it's the specified width.
1178Note that the \code{\%} operator is still more flexible and powerful
1179than \method{zfill()}.
1180
1181\begin{verbatim}
1182>>> '45'.zfill(4)
1183'0045'
1184>>> '12345'.zfill(4)
1185'12345'
1186>>> 'goofy'.zfill(6)
1187'0goofy'
1188\end{verbatim}
1189
Andrew M. Kuchling346386f2002-07-12 20:24:42 +00001190(Contributed by Walter D\"orwald.)
1191
Fred Drake5c4cf152002-11-13 14:59:06 +00001192\item A new type object, \class{basestring}, has been added.
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +00001193 Both 8-bit strings and Unicode strings inherit from this type, so
1194 \code{isinstance(obj, basestring)} will return \constant{True} for
1195 either kind of string. It's a completely abstract type, so you
1196 can't create \class{basestring} instances.
1197
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001198\item Interned strings are no longer immortal, and will now be
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001199garbage-collected in the usual way when the only reference to them is
1200from the internal dictionary of interned strings. (Implemented by
1201Oren Tirosh.)
1202
1203\end{itemize}
1204
1205
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +00001206%======================================================================
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001207\subsection{Optimizations}
1208
1209\begin{itemize}
1210
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +00001211\item The creation of new-style class instances has been made much
1212faster; they're now faster than classic classes!
1213
Andrew M. Kuchling950725f2002-08-06 01:40:48 +00001214\item The \method{sort()} method of list objects has been extensively
1215rewritten by Tim Peters, and the implementation is significantly
1216faster.
1217
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001218\item Multiplication of large long integers is now much faster thanks
1219to an implementation of Karatsuba multiplication, an algorithm that
1220scales better than the O(n*n) required for the grade-school
1221multiplication algorithm. (Original patch by Christopher A. Craig,
1222and significantly reworked by Tim Peters.)
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +00001223
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001224\item The \code{SET_LINENO} opcode is now gone. This may provide a
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001225small speed increase, depending on your compiler's idiosyncrasies.
1226See section~\ref{section-other} for a longer explanation.
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001227(Removed by Michael Hudson.)
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +00001228
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001229\item \function{xrange()} objects now have their own iterator, making
1230\code{for i in xrange(n)} slightly faster than
1231\code{for i in range(n)}. (Patch by Raymond Hettinger.)
1232
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001233\item A number of small rearrangements have been made in various
1234hotspots to improve performance, inlining a function here, removing
1235some code there. (Implemented mostly by GvR, but lots of people have
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001236contributed single changes.)
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +00001237
1238\end{itemize}
Neal Norwitzd68f5172002-05-29 15:54:55 +00001239
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +00001240
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001241%======================================================================
Andrew M. Kuchlingef893fe2003-01-06 20:04:17 +00001242\section{New, Improved, and Deprecated Modules}
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00001243
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001244As usual, Python's standard library received a number of enhancements and
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001245bug fixes. Here's a partial list of the most notable changes, sorted
1246alphabetically by module name. Consult the
1247\file{Misc/NEWS} file in the source tree for a more
1248complete list of changes, or look through the CVS logs for all the
1249details.
Andrew M. Kuchling821013e2002-05-06 17:46:39 +00001250
1251\begin{itemize}
1252
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001253\item The \module{array} module now supports arrays of Unicode
Fred Drake5c4cf152002-11-13 14:59:06 +00001254characters using the \character{u} format character. Arrays also now
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001255support using the \code{+=} assignment operator to add another array's
1256contents, and the \code{*=} assignment operator to repeat an array.
1257(Contributed by Jason Orendorff.)
1258
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001259\item The \module{bsddb} module has been replaced by version 4.1.1
Andrew M. Kuchling669249e2002-11-19 13:05:33 +00001260of the \ulink{PyBSDDB}{http://pybsddb.sourceforge.net} package,
1261providing a more complete interface to the transactional features of
1262the BerkeleyDB library.
1263The old version of the module has been renamed to
1264\module{bsddb185} and is no longer built automatically; you'll
1265have to edit \file{Modules/Setup} to enable it. Note that the new
1266\module{bsddb} package is intended to be compatible with the
1267old module, so be sure to file bugs if you discover any
1268incompatibilities.
1269
Fred Drake5c4cf152002-11-13 14:59:06 +00001270\item The Distutils \class{Extension} class now supports
1271an extra constructor argument named \var{depends} for listing
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001272additional source files that an extension depends on. This lets
1273Distutils recompile the module if any of the dependency files are
Fred Drake5c4cf152002-11-13 14:59:06 +00001274modified. For example, if \file{sampmodule.c} includes the header
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001275file \file{sample.h}, you would create the \class{Extension} object like
1276this:
1277
1278\begin{verbatim}
1279ext = Extension("samp",
1280 sources=["sampmodule.c"],
1281 depends=["sample.h"])
1282\end{verbatim}
1283
1284Modifying \file{sample.h} would then cause the module to be recompiled.
1285(Contributed by Jeremy Hylton.)
1286
Andrew M. Kuchlingdc3f7e12002-11-04 20:05:10 +00001287\item Other minor changes to Distutils:
1288it now checks for the \envvar{CC}, \envvar{CFLAGS}, \envvar{CPP},
1289\envvar{LDFLAGS}, and \envvar{CPPFLAGS} environment variables, using
1290them to override the settings in Python's configuration (contributed
Andrew M. Kuchlinga31bb372003-01-27 16:36:34 +00001291by Robert Weber).
Andrew M. Kuchlingdc3f7e12002-11-04 20:05:10 +00001292
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001293\item The \module{getopt} module gained a new function,
1294\function{gnu_getopt()}, that supports the same arguments as the existing
Fred Drake5c4cf152002-11-13 14:59:06 +00001295\function{getopt()} function but uses GNU-style scanning mode.
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001296The existing \function{getopt()} stops processing options as soon as a
1297non-option argument is encountered, but in GNU-style mode processing
1298continues, meaning that options and arguments can be mixed. For
1299example:
1300
1301\begin{verbatim}
1302>>> getopt.getopt(['-f', 'filename', 'output', '-v'], 'f:v')
1303([('-f', 'filename')], ['output', '-v'])
1304>>> getopt.gnu_getopt(['-f', 'filename', 'output', '-v'], 'f:v')
1305([('-f', 'filename'), ('-v', '')], ['output'])
1306\end{verbatim}
1307
1308(Contributed by Peter \AA{strand}.)
1309
1310\item The \module{grp}, \module{pwd}, and \module{resource} modules
Fred Drake5c4cf152002-11-13 14:59:06 +00001311now return enhanced tuples:
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001312
1313\begin{verbatim}
1314>>> import grp
1315>>> g = grp.getgrnam('amk')
1316>>> g.gr_name, g.gr_gid
1317('amk', 500)
1318\end{verbatim}
1319
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +00001320\item The \module{gzip} module can now handle files exceeding 2~Gb.
1321
Andrew M. Kuchling950725f2002-08-06 01:40:48 +00001322\item The new \module{heapq} module contains an implementation of a
1323heap queue algorithm. A heap is an array-like data structure that
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001324keeps items in a partially sorted order such that, for every index
1325\var{k}, \code{heap[\var{k}] <= heap[2*\var{k}+1]} and
1326\code{heap[\var{k}] <= heap[2*\var{k}+2]}. This makes it quick to
1327remove the smallest item, and inserting a new item while maintaining
1328the heap property is O(lg~n). (See
Andrew M. Kuchling950725f2002-08-06 01:40:48 +00001329\url{http://www.nist.gov/dads/HTML/priorityque.html} for more
1330information about the priority queue data structure.)
1331
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00001332The \module{heapq} module provides \function{heappush()} and
Andrew M. Kuchling950725f2002-08-06 01:40:48 +00001333\function{heappop()} functions for adding and removing items while
1334maintaining the heap property on top of some other mutable Python
1335sequence type. For example:
1336
1337\begin{verbatim}
1338>>> import heapq
1339>>> heap = []
1340>>> for item in [3, 7, 5, 11, 1]:
1341... heapq.heappush(heap, item)
1342...
1343>>> heap
1344[1, 3, 5, 11, 7]
1345>>> heapq.heappop(heap)
13461
1347>>> heapq.heappop(heap)
13483
1349>>> heap
1350[5, 7, 11]
Andrew M. Kuchling950725f2002-08-06 01:40:48 +00001351\end{verbatim}
1352
1353(Contributed by Kevin O'Connor.)
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001354
Andrew M. Kuchling87cebbf2003-01-03 16:24:28 +00001355\item The \module{imaplib} module now supports IMAP over SSL.
1356(Contributed by Piers Lauder and Tino Lange.)
1357
Fred Drake5c4cf152002-11-13 14:59:06 +00001358\item Two new functions in the \module{math} module,
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001359\function{degrees(\var{rads})} and \function{radians(\var{degs})},
Fred Drake5c4cf152002-11-13 14:59:06 +00001360convert between radians and degrees. Other functions in the
Andrew M. Kuchling8e5b53b2002-12-15 20:17:38 +00001361\module{math} module such as \function{math.sin()} and
1362\function{math.cos()} have always required input values measured in
1363radians. Also, an optional \var{base} argument was added to
1364\function{math.log()} to make it easier to compute logarithms for
1365bases other than \code{e} and \code{10}. (Contributed by Raymond
1366Hettinger.)
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001367
Andrew M. Kuchlingae3bbf52002-12-31 14:03:45 +00001368\item Several new functions (\function{getpgid()}, \function{killpg()},
1369\function{lchown()}, \function{loadavg()}, \function{major()}, \function{makedev()},
1370\function{minor()}, and \function{mknod()}) were added to the
Andrew M. Kuchlingc309cca2002-10-10 16:04:08 +00001371\module{posix} module that underlies the \module{os} module.
Andrew M. Kuchlingae3bbf52002-12-31 14:03:45 +00001372(Contributed by Gustavo Niemeyer, Geert Jansen, and Denis S. Otkidach.)
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001373
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001374\item In the \module{os} module, the \function{*stat()} family of functions can now report
1375fractions of a second in a timestamp. Such time stamps are
1376represented as floats, similar to \function{time.time()}.
1377
1378During testing, it was found that some applications will break if time
1379stamps are floats. For compatibility, when using the tuple interface
1380of the \class{stat_result} time stamps will be represented as integers.
1381When using named fields (a feature first introduced in Python 2.2),
1382time stamps are still represented as integers, unless
1383\function{os.stat_float_times()} is invoked to enable float return
1384values:
1385
1386\begin{verbatim}
1387>>> os.stat("/tmp").st_mtime
13881034791200
1389>>> os.stat_float_times(True)
1390>>> os.stat("/tmp").st_mtime
13911034791200.6335014
1392\end{verbatim}
1393
1394In Python 2.4, the default will change to always returning floats.
1395
1396Application developers should enable this feature only if all their
1397libraries work properly when confronted with floating point time
1398stamps, or if they use the tuple API. If used, the feature should be
1399activated on an application level instead of trying to enable it on a
1400per-use basis.
1401
Andrew M. Kuchling53262572002-12-01 14:00:21 +00001402\item The old and never-documented \module{linuxaudiodev} module has
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001403been deprecated, and a new version named \module{ossaudiodev} has been
1404added. The module was renamed because the OSS sound drivers can be
1405used on platforms other than Linux, and the interface has also been
1406tidied and brought up to date in various ways. (Contributed by Greg
Greg Wardaa1d3aa2003-01-03 18:03:21 +00001407Ward and Nicholas FitzRoy-Dale.)
Andrew M. Kuchling53262572002-12-01 14:00:21 +00001408
Fred Drake5c4cf152002-11-13 14:59:06 +00001409\item The parser objects provided by the \module{pyexpat} module
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001410can now optionally buffer character data, resulting in fewer calls to
1411your character data handler and therefore faster performance. Setting
Fred Drake5c4cf152002-11-13 14:59:06 +00001412the parser object's \member{buffer_text} attribute to \constant{True}
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001413will enable buffering.
1414
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00001415\item The \function{sample(\var{population}, \var{k})} function was
1416added to the \module{random} module. \var{population} is a sequence
Fred Drakeaac8c582003-01-17 22:50:10 +00001417or \class{xrange} object containing the elements of a population, and
1418\function{sample()}
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00001419chooses \var{k} elements from the population without replacing chosen
1420elements. \var{k} can be any value up to \code{len(\var{population})}.
1421For example:
1422
1423\begin{verbatim}
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001424>>> days = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'St', 'Sn']
Michael W. Hudsoncfd38842002-12-17 16:15:34 +00001425>>> random.sample(days, 3) # Choose 3 elements
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001426['St', 'Sn', 'Th']
Michael W. Hudsoncfd38842002-12-17 16:15:34 +00001427>>> random.sample(days, 7) # Choose 7 elements
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001428['Tu', 'Th', 'Mo', 'We', 'St', 'Fr', 'Sn']
Michael W. Hudsoncfd38842002-12-17 16:15:34 +00001429>>> random.sample(days, 7) # Choose 7 again
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001430['We', 'Mo', 'Sn', 'Fr', 'Tu', 'St', 'Th']
Michael W. Hudsoncfd38842002-12-17 16:15:34 +00001431>>> random.sample(days, 8) # Can't choose eight
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00001432Traceback (most recent call last):
Andrew M. Kuchling28f2f882002-11-14 14:14:16 +00001433 File "<stdin>", line 1, in ?
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001434 File "random.py", line 414, in sample
1435 raise ValueError, "sample larger than population"
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00001436ValueError: sample larger than population
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001437>>> random.sample(xrange(1,10000,2), 10) # Choose ten odd nos. under 10000
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001438[3407, 3805, 1505, 7023, 2401, 2267, 9733, 3151, 8083, 9195]
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00001439\end{verbatim}
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +00001440
1441The \module{random} module now uses a new algorithm, the Mersenne
1442Twister, implemented in C. It's faster and more extensively studied
1443than the previous algorithm.
1444
1445(All changes contributed by Raymond Hettinger.)
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00001446
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001447\item The \module{readline} module also gained a number of new
1448functions: \function{get_history_item()},
1449\function{get_current_history_length()}, and \function{redisplay()}.
1450
Andrew M. Kuchlingef893fe2003-01-06 20:04:17 +00001451\item The \module{rexec} and \module{Bastion} modules have been
1452declared dead, and attempts to import them will fail with a
1453\exception{RuntimeError}. New-style classes provide new ways to break
1454out of the restricted execution environment provided by
1455\module{rexec}, and no one has interest in fixing them or time to do
1456so. If you have applications using \module{rexec}, rewrite them to
1457use something else.
1458
1459(Sticking with Python 2.2 or 2.1 will not make your applications any
1460safer, because there are known bugs in the \module{rexec} module in
1461those versions. I repeat, if you're using \module{rexec}, stop using
1462it immediately.)
1463
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +00001464\item The \module{shutil} module gained a \function{move(\var{src},
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001465\var{dest})} function that recursively moves a file or directory to a new
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +00001466location.
1467
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001468\item Support for more advanced POSIX signal handling was added
1469to the \module{signal} module by adding the \function{sigpending},
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001470\function{sigprocmask} and \function{sigsuspend} functions where supported
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001471by the platform. These functions make it possible to avoid some previously
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001472unavoidable race conditions with signal handling.
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001473
1474\item The \module{socket} module now supports timeouts. You
1475can call the \method{settimeout(\var{t})} method on a socket object to
1476set a timeout of \var{t} seconds. Subsequent socket operations that
1477take longer than \var{t} seconds to complete will abort and raise a
Fred Drake5c4cf152002-11-13 14:59:06 +00001478\exception{socket.error} exception.
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001479
1480The original timeout implementation was by Tim O'Malley. Michael
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001481Gilfix integrated it into the Python \module{socket} module and
1482shepherded it through a lengthy review. After the code was checked
1483in, Guido van~Rossum rewrote parts of it. (This is a good example of
1484a collaborative development process in action.)
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +00001485
Mark Hammond8af50bc2002-12-03 06:13:35 +00001486\item On Windows, the \module{socket} module now ships with Secure
1487Sockets Library (SSL) support.
1488
Fred Drake5c4cf152002-11-13 14:59:06 +00001489\item The value of the C \constant{PYTHON_API_VERSION} macro is now exposed
Fred Drake583db0d2002-09-14 02:03:25 +00001490at the Python level as \code{sys.api_version}.
Andrew M. Kuchlingdcfd8252002-09-13 22:21:42 +00001491
Andrew M. Kuchling674b0bf2003-01-07 00:07:19 +00001492\item The new \module{tarfile} module
Neal Norwitz55d555f2003-01-08 05:27:42 +00001493allows reading from and writing to \program{tar}-format archive files.
Andrew M. Kuchling674b0bf2003-01-07 00:07:19 +00001494(Contributed by Lars Gust\"abel.)
1495
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +00001496\item The new \module{textwrap} module contains functions for wrapping
Andrew M. Kuchlingd003a2a2002-06-26 13:23:55 +00001497strings containing paragraphs of text. The \function{wrap(\var{text},
1498\var{width})} function takes a string and returns a list containing
1499the text split into lines of no more than the chosen width. The
1500\function{fill(\var{text}, \var{width})} function returns a single
1501string, reformatted to fit into lines no longer than the chosen width.
1502(As you can guess, \function{fill()} is built on top of
1503\function{wrap()}. For example:
1504
1505\begin{verbatim}
1506>>> import textwrap
1507>>> paragraph = "Not a whit, we defy augury: ... more text ..."
1508>>> textwrap.wrap(paragraph, 60)
Fred Drake5c4cf152002-11-13 14:59:06 +00001509["Not a whit, we defy augury: there's a special providence in",
1510 "the fall of a sparrow. If it be now, 'tis not to come; if it",
Andrew M. Kuchlingd003a2a2002-06-26 13:23:55 +00001511 ...]
1512>>> print textwrap.fill(paragraph, 35)
1513Not a whit, we defy augury: there's
1514a special providence in the fall of
1515a sparrow. If it be now, 'tis not
1516to come; if it be not to come, it
1517will be now; if it be not now, yet
1518it will come: the readiness is all.
Fred Drake5c4cf152002-11-13 14:59:06 +00001519>>>
Andrew M. Kuchlingd003a2a2002-06-26 13:23:55 +00001520\end{verbatim}
1521
1522The module also contains a \class{TextWrapper} class that actually
Fred Drake5c4cf152002-11-13 14:59:06 +00001523implements the text wrapping strategy. Both the
Andrew M. Kuchlingd003a2a2002-06-26 13:23:55 +00001524\class{TextWrapper} class and the \function{wrap()} and
1525\function{fill()} functions support a number of additional keyword
1526arguments for fine-tuning the formatting; consult the module's
Fred Drake5c4cf152002-11-13 14:59:06 +00001527documentation for details.
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +00001528%XXX add a link to the module docs?
Andrew M. Kuchlingd003a2a2002-06-26 13:23:55 +00001529(Contributed by Greg Ward.)
1530
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +00001531\item The \module{thread} and \module{threading} modules now have
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001532companion modules, \module{dummy_thread} and \module{dummy_threading},
1533that provide a do-nothing implementation of the \module{thread}
1534module's interface for platforms where threads are not supported. The
1535intention is to simplify thread-aware modules (ones that \emph{don't}
1536rely on threads to run) by putting the following code at the top:
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +00001537
1538% XXX why as _threading?
1539\begin{verbatim}
1540try:
1541 import threading as _threading
1542except ImportError:
1543 import dummy_threading as _threading
1544\end{verbatim}
1545
1546Code can then call functions and use classes in \module{_threading}
1547whether or not threads are supported, avoiding an \keyword{if}
1548statement and making the code slightly clearer. This module will not
1549magically make multithreaded code run without threads; code that waits
1550for another thread to return or to do something will simply hang
1551forever.
1552
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001553\item The \module{time} module's \function{strptime()} function has
Fred Drake5c4cf152002-11-13 14:59:06 +00001554long been an annoyance because it uses the platform C library's
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001555\function{strptime()} implementation, and different platforms
1556sometimes have odd bugs. Brett Cannon contributed a portable
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001557implementation that's written in pure Python and should behave
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001558identically on all platforms.
1559
Andrew M. Kuchling6c50df22002-12-13 12:53:16 +00001560\item The \module{UserDict} module has a new \class{DictMixin} class which
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001561defines all dictionary methods for classes that already have a minimum
1562mapping interface. This greatly simplifies writing classes that need
1563to be substitutable for dictionaries, such as the classes in
1564the \module{shelve} module.
1565
1566Adding the mixin as a superclass provides the full dictionary
1567interface whenever the class defines \method{__getitem__},
Andrew M. Kuchling6c50df22002-12-13 12:53:16 +00001568\method{__setitem__}, \method{__delitem__}, and \method{keys}.
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001569For example:
1570
1571\begin{verbatim}
1572>>> import UserDict
1573>>> class SeqDict(UserDict.DictMixin):
1574 """Dictionary lookalike implemented with lists."""
1575 def __init__(self):
1576 self.keylist = []
1577 self.valuelist = []
1578 def __getitem__(self, key):
1579 try:
1580 i = self.keylist.index(key)
1581 except ValueError:
1582 raise KeyError
1583 return self.valuelist[i]
1584 def __setitem__(self, key, value):
1585 try:
1586 i = self.keylist.index(key)
1587 self.valuelist[i] = value
1588 except ValueError:
1589 self.keylist.append(key)
1590 self.valuelist.append(value)
1591 def __delitem__(self, key):
1592 try:
1593 i = self.keylist.index(key)
1594 except ValueError:
1595 raise KeyError
1596 self.keylist.pop(i)
1597 self.valuelist.pop(i)
1598 def keys(self):
1599 return list(self.keylist)
1600
1601>>> s = SeqDict()
1602>>> dir(s) # See that other dictionary methods are implemented
1603['__cmp__', '__contains__', '__delitem__', '__doc__', '__getitem__',
1604 '__init__', '__iter__', '__len__', '__module__', '__repr__',
1605 '__setitem__', 'clear', 'get', 'has_key', 'items', 'iteritems',
1606 'iterkeys', 'itervalues', 'keylist', 'keys', 'pop', 'popitem',
1607 'setdefault', 'update', 'valuelist', 'values']
Neal Norwitzc7d8c682002-12-24 14:51:43 +00001608\end{verbatim}
Andrew M. Kuchling449a87d2002-12-11 15:03:51 +00001609
1610(Contributed by Raymond Hettinger.)
1611
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +00001612\item The DOM implementation
1613in \module{xml.dom.minidom} can now generate XML output in a
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001614particular encoding by providing an optional encoding argument to
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +00001615the \method{toxml()} and \method{toprettyxml()} methods of DOM nodes.
1616
Andrew M. Kuchlingef893fe2003-01-06 20:04:17 +00001617item The \module{Tix} module has received various bug fixes and
1618updates for the current version of the Tix package.
1619
Andrew M. Kuchling6c50df22002-12-13 12:53:16 +00001620\item The \module{Tkinter} module now works with a thread-enabled
1621version of Tcl. Tcl's threading model requires that widgets only be
1622accessed from the thread in which they're created; accesses from
1623another thread can cause Tcl to panic. For certain Tcl interfaces,
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001624\module{Tkinter} will now automatically avoid this
1625when a widget is accessed from a different thread by marshalling a
1626command, passing it to the correct thread, and waiting for the
1627results. Other interfaces can't be handled automatically but
1628\module{Tkinter} will now raise an exception on such an access so that
1629at least you can find out about the problem. See
Andrew M. Kuchling6c50df22002-12-13 12:53:16 +00001630\url{http://mail.python.org/pipermail/python-dev/2002-December/031107.html}
1631for a more detailed explanation of this change. (Implemented by
1632Martin von L\"owis.)
1633
Andrew M. Kuchlingb492fa92002-11-27 19:11:10 +00001634\item Calling Tcl methods through \module{_tkinter} no longer
1635returns only strings. Instead, if Tcl returns other objects those
1636objects are converted to their Python equivalent, if one exists, or
1637wrapped with a \class{_tkinter.Tcl_Obj} object if no Python equivalent
Raymond Hettinger45bda572002-12-14 20:20:45 +00001638exists. This behavior can be controlled through the
Andrew M. Kuchlingb492fa92002-11-27 19:11:10 +00001639\method{wantobjects()} method of \class{tkapp} objects.
Martin v. Löwis39b48522002-11-26 09:47:25 +00001640
Andrew M. Kuchlingb492fa92002-11-27 19:11:10 +00001641When using \module{_tkinter} through the \module{Tkinter} module (as
1642most Tkinter applications will), this feature is always activated. It
1643should not cause compatibility problems, since Tkinter would always
1644convert string results to Python types where possible.
Martin v. Löwis39b48522002-11-26 09:47:25 +00001645
Raymond Hettinger45bda572002-12-14 20:20:45 +00001646If any incompatibilities are found, the old behavior can be restored
Andrew M. Kuchlingb492fa92002-11-27 19:11:10 +00001647by setting the \member{wantobjects} variable in the \module{Tkinter}
1648module to false before creating the first \class{tkapp} object.
Martin v. Löwis39b48522002-11-26 09:47:25 +00001649
1650\begin{verbatim}
1651import Tkinter
Martin v. Löwis8c8aa5d2002-11-26 21:39:48 +00001652Tkinter.wantobjects = 0
Martin v. Löwis39b48522002-11-26 09:47:25 +00001653\end{verbatim}
1654
Andrew M. Kuchling6c50df22002-12-13 12:53:16 +00001655Any breakage caused by this change should be reported as a bug.
Martin v. Löwis39b48522002-11-26 09:47:25 +00001656
Andrew M. Kuchling821013e2002-05-06 17:46:39 +00001657\end{itemize}
1658
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00001659
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001660%======================================================================
Andrew M. Kuchlinga974b392003-01-13 19:09:03 +00001661\subsection{Date/Time Type}
1662
1663Date and time types suitable for expressing timestamps were added as
1664the \module{datetime} module. The types don't support different
1665calendars or many fancy features, and just stick to the basics of
1666representing time.
1667
1668The three primary types are: \class{date}, representing a day, month,
1669and year; \class{time}, consisting of hour, minute, and second; and
1670\class{datetime}, which contains all the attributes of both
1671\class{date} and \class{time}. These basic types don't understand
1672time zones, but there are subclasses named \class{timetz} and
1673\class{datetimetz} that do. There's also a
1674\class{timedelta} class representing a difference between two points
1675in time, and time zone logic is implemented by classes inheriting from
1676the abstract \class{tzinfo} class.
1677
1678You can create instances of \class{date} and \class{time} by either
1679supplying keyword arguments to the appropriate constructor,
1680e.g. \code{datetime.date(year=1972, month=10, day=15)}, or by using
1681one of a number of class methods. For example, the \method{today()}
1682class method returns the current local date.
1683
1684Once created, instances of the date/time classes are all immutable.
1685There are a number of methods for producing formatted strings from
1686objects:
1687
1688\begin{verbatim}
1689>>> import datetime
1690>>> now = datetime.datetime.now()
1691>>> now.isoformat()
1692'2002-12-30T21:27:03.994956'
1693>>> now.ctime() # Only available on date, datetime
1694'Mon Dec 30 21:27:03 2002'
Raymond Hettingeree1bded2003-01-17 16:20:23 +00001695>>> now.strftime('%Y %d %b')
Andrew M. Kuchlinga974b392003-01-13 19:09:03 +00001696'2002 30 Dec'
1697\end{verbatim}
1698
1699The \method{replace()} method allows modifying one or more fields
1700of a \class{date} or \class{datetime} instance:
1701
1702\begin{verbatim}
1703>>> d = datetime.datetime.now()
1704>>> d
1705datetime.datetime(2002, 12, 30, 22, 15, 38, 827738)
1706>>> d.replace(year=2001, hour = 12)
1707datetime.datetime(2001, 12, 30, 12, 15, 38, 827738)
1708>>>
1709\end{verbatim}
1710
1711Instances can be compared, hashed, and converted to strings (the
1712result is the same as that of \method{isoformat()}). \class{date} and
1713\class{datetime} instances can be subtracted from each other, and
1714added to \class{timedelta} instances.
1715
1716For more information, refer to the \ulink{module's reference
Fred Drake693aea22003-02-07 14:52:18 +00001717documentation}{..//lib/module-datetime.html}.
Andrew M. Kuchlinga974b392003-01-13 19:09:03 +00001718(Contributed by Tim Peters.)
1719
1720
1721%======================================================================
Andrew M. Kuchling24d5a522002-11-14 23:40:42 +00001722\subsection{The \module{optparse} Module}
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +00001723
Andrew M. Kuchling24d5a522002-11-14 23:40:42 +00001724The \module{getopt} module provides simple parsing of command-line
1725arguments. The new \module{optparse} module (originally named Optik)
1726provides more elaborate command-line parsing that follows the Unix
1727conventions, automatically creates the output for \longprogramopt{help},
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001728and can perform different actions for different options.
Andrew M. Kuchling24d5a522002-11-14 23:40:42 +00001729
1730You start by creating an instance of \class{OptionParser} and telling
1731it what your program's options are.
1732
1733\begin{verbatim}
1734from optparse import OptionParser
1735
1736op = OptionParser()
1737op.add_option('-i', '--input',
1738 action='store', type='string', dest='input',
1739 help='set input filename')
1740op.add_option('-l', '--length',
1741 action='store', type='int', dest='length',
1742 help='set maximum length of output')
1743\end{verbatim}
1744
1745Parsing a command line is then done by calling the \method{parse_args()}
1746method.
1747
1748\begin{verbatim}
1749options, args = op.parse_args(sys.argv[1:])
1750print options
1751print args
1752\end{verbatim}
1753
1754This returns an object containing all of the option values,
1755and a list of strings containing the remaining arguments.
1756
1757Invoking the script with the various arguments now works as you'd
1758expect it to. Note that the length argument is automatically
1759converted to an integer.
1760
1761\begin{verbatim}
1762$ ./python opt.py -i data arg1
1763<Values at 0x400cad4c: {'input': 'data', 'length': None}>
1764['arg1']
1765$ ./python opt.py --input=data --length=4
1766<Values at 0x400cad2c: {'input': 'data', 'length': 4}>
1767['arg1']
1768$
1769\end{verbatim}
1770
1771The help message is automatically generated for you:
1772
1773\begin{verbatim}
1774$ ./python opt.py --help
1775usage: opt.py [options]
1776
1777options:
1778 -h, --help show this help message and exit
1779 -iINPUT, --input=INPUT
1780 set input filename
1781 -lLENGTH, --length=LENGTH
1782 set maximum length of output
1783$
1784\end{verbatim}
Andrew M. Kuchling669249e2002-11-19 13:05:33 +00001785% $ prevent Emacs tex-mode from getting confused
Andrew M. Kuchling24d5a522002-11-14 23:40:42 +00001786
1787Optik was written by Greg Ward, with suggestions from the readers of
1788the Getopt SIG.
1789
1790\begin{seealso}
Fred Drake693aea22003-02-07 14:52:18 +00001791\seeurl{http://optik.sourceforge.net/}
Andrew M. Kuchling24d5a522002-11-14 23:40:42 +00001792{The Optik site has tutorial and reference documentation for
1793\module{optparse}.
1794% XXX change to point to Python docs, when those docs get written.
1795}
1796\end{seealso}
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +00001797
1798
1799%======================================================================
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001800\section{Specialized Object Allocator (pymalloc)\label{section-pymalloc}}
1801
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001802An experimental feature added to Python 2.1 was pymalloc, a
1803specialized object allocator written by Vladimir Marangozov. Pymalloc
1804is intended to be faster than the system \cfunction{malloc()} and
1805to have less memory overhead for allocation patterns typical of Python
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001806programs. The allocator uses C's \cfunction{malloc()} function to get
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001807large pools of memory and then fulfills smaller memory requests from
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001808these pools.
1809
1810In 2.1 and 2.2, pymalloc was an experimental feature and wasn't
1811enabled by default; you had to explicitly turn it on by providing the
1812\longprogramopt{with-pymalloc} option to the \program{configure}
1813script. In 2.3, pymalloc has had further enhancements and is now
1814enabled by default; you'll have to supply
1815\longprogramopt{without-pymalloc} to disable it.
1816
1817This change is transparent to code written in Python; however,
1818pymalloc may expose bugs in C extensions. Authors of C extension
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001819modules should test their code with pymalloc enabled,
1820because some incorrect code may cause core dumps at runtime.
1821
1822There's one particularly common error that causes problems. There are
1823a number of memory allocation functions in Python's C API that have
1824previously just been aliases for the C library's \cfunction{malloc()}
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001825and \cfunction{free()}, meaning that if you accidentally called
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001826mismatched functions the error wouldn't be noticeable. When the
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001827object allocator is enabled, these functions aren't aliases of
1828\cfunction{malloc()} and \cfunction{free()} any more, and calling the
1829wrong function to free memory may get you a core dump. For example,
1830if memory was allocated using \cfunction{PyObject_Malloc()}, it has to
1831be freed using \cfunction{PyObject_Free()}, not \cfunction{free()}. A
1832few modules included with Python fell afoul of this and had to be
1833fixed; doubtless there are more third-party modules that will have the
1834same problem.
1835
1836As part of this change, the confusing multiple interfaces for
1837allocating memory have been consolidated down into two API families.
1838Memory allocated with one family must not be manipulated with
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001839functions from the other family. There is one family for allocating
1840chunks of memory, and another family of functions specifically for
1841allocating Python objects.
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001842
1843\begin{itemize}
1844 \item To allocate and free an undistinguished chunk of memory use
1845 the ``raw memory'' family: \cfunction{PyMem_Malloc()},
1846 \cfunction{PyMem_Realloc()}, and \cfunction{PyMem_Free()}.
1847
1848 \item The ``object memory'' family is the interface to the pymalloc
1849 facility described above and is biased towards a large number of
1850 ``small'' allocations: \cfunction{PyObject_Malloc},
1851 \cfunction{PyObject_Realloc}, and \cfunction{PyObject_Free}.
1852
1853 \item To allocate and free Python objects, use the ``object'' family
1854 \cfunction{PyObject_New()}, \cfunction{PyObject_NewVar()}, and
1855 \cfunction{PyObject_Del()}.
1856\end{itemize}
1857
1858Thanks to lots of work by Tim Peters, pymalloc in 2.3 also provides
1859debugging features to catch memory overwrites and doubled frees in
1860both extension modules and in the interpreter itself. To enable this
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001861support, compile a debugging version of the Python interpreter by
1862running \program{configure} with \longprogramopt{with-pydebug}.
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001863
1864To aid extension writers, a header file \file{Misc/pymemcompat.h} is
1865distributed with the source to Python 2.3 that allows Python
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001866extensions to use the 2.3 interfaces to memory allocation while
1867compiling against any version of Python since 1.5.2. You would copy
1868the file from Python's source distribution and bundle it with the
1869source of your extension.
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001870
1871\begin{seealso}
1872
1873\seeurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Objects/obmalloc.c}
1874{For the full details of the pymalloc implementation, see
1875the comments at the top of the file \file{Objects/obmalloc.c} in the
1876Python source code. The above link points to the file within the
1877SourceForge CVS browser.}
1878
1879\end{seealso}
1880
1881
Andrew M. Kuchling821013e2002-05-06 17:46:39 +00001882% ======================================================================
1883\section{Build and C API Changes}
1884
Andrew M. Kuchling3c305d92002-07-22 18:50:11 +00001885Changes to Python's build process and to the C API include:
Andrew M. Kuchling821013e2002-05-06 17:46:39 +00001886
1887\begin{itemize}
1888
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +00001889\item The C-level interface to the garbage collector has been changed,
1890to make it easier to write extension types that support garbage
1891collection, and to make it easier to debug misuses of the functions.
1892Various functions have slightly different semantics, so a bunch of
1893functions had to be renamed. Extensions that use the old API will
1894still compile but will \emph{not} participate in garbage collection,
1895so updating them for 2.3 should be considered fairly high priority.
1896
1897To upgrade an extension module to the new API, perform the following
1898steps:
1899
1900\begin{itemize}
1901
1902\item Rename \cfunction{Py_TPFLAGS_GC} to \cfunction{PyTPFLAGS_HAVE_GC}.
1903
1904\item Use \cfunction{PyObject_GC_New} or \cfunction{PyObject_GC_NewVar} to
1905allocate objects, and \cfunction{PyObject_GC_Del} to deallocate them.
1906
1907\item Rename \cfunction{PyObject_GC_Init} to \cfunction{PyObject_GC_Track} and
1908\cfunction{PyObject_GC_Fini} to \cfunction{PyObject_GC_UnTrack}.
1909
1910\item Remove \cfunction{PyGC_HEAD_SIZE} from object size calculations.
1911
1912\item Remove calls to \cfunction{PyObject_AS_GC} and \cfunction{PyObject_FROM_GC}.
1913
1914\end{itemize}
1915
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001916\item The cycle detection implementation used by the garbage collection
1917has proven to be stable, so it's now being made mandatory; you can no
1918longer compile Python without it, and the
1919\longprogramopt{with-cycle-gc} switch to \program{configure} has been removed.
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +00001920
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001921\item Python can now optionally be built as a shared library
1922(\file{libpython2.3.so}) by supplying \longprogramopt{enable-shared}
Fred Drake5c4cf152002-11-13 14:59:06 +00001923when running Python's \program{configure} script. (Contributed by Ondrej
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +00001924Palkovsky.)
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +00001925
Michael W. Hudsondd32a912002-08-15 14:59:02 +00001926\item The \csimplemacro{DL_EXPORT} and \csimplemacro{DL_IMPORT} macros
1927are now deprecated. Initialization functions for Python extension
1928modules should now be declared using the new macro
Andrew M. Kuchling3c305d92002-07-22 18:50:11 +00001929\csimplemacro{PyMODINIT_FUNC}, while the Python core will generally
1930use the \csimplemacro{PyAPI_FUNC} and \csimplemacro{PyAPI_DATA}
1931macros.
Neal Norwitzbba23a82002-07-22 13:18:59 +00001932
Fred Drake5c4cf152002-11-13 14:59:06 +00001933\item The interpreter can be compiled without any docstrings for
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +00001934the built-in functions and modules by supplying
Fred Drake5c4cf152002-11-13 14:59:06 +00001935\longprogramopt{without-doc-strings} to the \program{configure} script.
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +00001936This makes the Python executable about 10\% smaller, but will also
1937mean that you can't get help for Python's built-ins. (Contributed by
1938Gustavo Niemeyer.)
1939
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001940\item The \cfunction{PyArg_NoArgs()} macro is now deprecated, and code
Andrew M. Kuchling7845e7c2002-07-11 19:27:46 +00001941that uses it should be changed. For Python 2.2 and later, the method
1942definition table can specify the
Fred Drake5c4cf152002-11-13 14:59:06 +00001943\constant{METH_NOARGS} flag, signalling that there are no arguments, and
Andrew M. Kuchling7845e7c2002-07-11 19:27:46 +00001944the argument checking can then be removed. If compatibility with
1945pre-2.2 versions of Python is important, the code could use
Fred Drakeaac8c582003-01-17 22:50:10 +00001946\code{PyArg_ParseTuple(\var{args}, "")} instead, but this will be slower
Andrew M. Kuchling7845e7c2002-07-11 19:27:46 +00001947than using \constant{METH_NOARGS}.
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00001948
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001949\item A new function, \cfunction{PyObject_DelItemString(\var{mapping},
1950char *\var{key})} was added
Fred Drake5c4cf152002-11-13 14:59:06 +00001951as shorthand for
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001952\code{PyObject_DelItem(\var{mapping}, PyString_New(\var{key})}.
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00001953
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +00001954\item The \method{xreadlines()} method of file objects, introduced in
1955Python 2.1, is no longer necessary because files now behave as their
1956own iterator. \method{xreadlines()} was originally introduced as a
1957faster way to loop over all the lines in a file, but now you can
1958simply write \code{for line in file_obj}.
1959
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001960\item File objects now manage their internal string buffer
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00001961differently, increasing it exponentially when needed. This results in
1962the benchmark tests in \file{Lib/test/test_bufio.py} speeding up
1963considerably (from 57 seconds to 1.7 seconds, according to one
1964measurement).
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001965
Andrew M. Kuchling72b58e02002-05-29 17:30:34 +00001966\item It's now possible to define class and static methods for a C
1967extension type by setting either the \constant{METH_CLASS} or
1968\constant{METH_STATIC} flags in a method's \ctype{PyMethodDef}
1969structure.
Andrew M. Kuchling45afd542002-04-02 14:25:25 +00001970
Andrew M. Kuchling346386f2002-07-12 20:24:42 +00001971\item Python now includes a copy of the Expat XML parser's source code,
1972removing any dependence on a system version or local installation of
Fred Drake5c4cf152002-11-13 14:59:06 +00001973Expat.
Andrew M. Kuchling346386f2002-07-12 20:24:42 +00001974
Andrew M. Kuchling821013e2002-05-06 17:46:39 +00001975\end{itemize}
1976
Andrew M. Kuchling366c10c2002-11-14 23:07:57 +00001977
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +00001978%======================================================================
Andrew M. Kuchling821013e2002-05-06 17:46:39 +00001979\subsection{Port-Specific Changes}
1980
Andrew M. Kuchling187b1d82002-05-29 19:20:57 +00001981Support for a port to IBM's OS/2 using the EMX runtime environment was
1982merged into the main Python source tree. EMX is a POSIX emulation
1983layer over the OS/2 system APIs. The Python port for EMX tries to
1984support all the POSIX-like capability exposed by the EMX runtime, and
1985mostly succeeds; \function{fork()} and \function{fcntl()} are
1986restricted by the limitations of the underlying emulation layer. The
1987standard OS/2 port, which uses IBM's Visual Age compiler, also gained
1988support for case-sensitive import semantics as part of the integration
1989of the EMX port into CVS. (Contributed by Andrew MacIntyre.)
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00001990
Andrew M. Kuchling72b58e02002-05-29 17:30:34 +00001991On MacOS, most toolbox modules have been weaklinked to improve
1992backward compatibility. This means that modules will no longer fail
1993to load if a single routine is missing on the curent OS version.
Andrew M. Kuchling187b1d82002-05-29 19:20:57 +00001994Instead calling the missing routine will raise an exception.
1995(Contributed by Jack Jansen.)
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00001996
Andrew M. Kuchling187b1d82002-05-29 19:20:57 +00001997The RPM spec files, found in the \file{Misc/RPM/} directory in the
1998Python source distribution, were updated for 2.3. (Contributed by
1999Sean Reifschneider.)
Fred Drake03e10312002-03-26 19:17:43 +00002000
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00002001Other new platforms now supported by Python include AtheOS
Fred Drake693aea22003-02-07 14:52:18 +00002002(\url{http://www.atheos.cx/}), GNU/Hurd, and OpenVMS.
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +00002003
Fred Drake03e10312002-03-26 19:17:43 +00002004
2005%======================================================================
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00002006\section{Other Changes and Fixes \label{section-other}}
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00002007
Andrew M. Kuchling7a82b8c2002-11-04 20:17:24 +00002008As usual, there were a bunch of other improvements and bugfixes
2009scattered throughout the source tree. A search through the CVS change
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00002010logs finds there were 121 patches applied and 103 bugs fixed between
Andrew M. Kuchling7a82b8c2002-11-04 20:17:24 +00002011Python 2.2 and 2.3. Both figures are likely to be underestimates.
2012
2013Some of the more notable changes are:
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00002014
2015\begin{itemize}
2016
Fred Drake54fe3fd2002-11-26 22:07:35 +00002017\item The \file{regrtest.py} script now provides a way to allow ``all
2018resources except \var{foo}.'' A resource name passed to the
2019\programopt{-u} option can now be prefixed with a hyphen
2020(\character{-}) to mean ``remove this resource.'' For example, the
2021option `\code{\programopt{-u}all,-bsddb}' could be used to enable the
2022use of all resources except \code{bsddb}.
2023
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00002024\item The tools used to build the documentation now work under Cygwin
2025as well as \UNIX.
2026
Michael W. Hudsondd32a912002-08-15 14:59:02 +00002027\item The \code{SET_LINENO} opcode has been removed. Back in the
2028mists of time, this opcode was needed to produce line numbers in
2029tracebacks and support trace functions (for, e.g., \module{pdb}).
2030Since Python 1.5, the line numbers in tracebacks have been computed
2031using a different mechanism that works with ``python -O''. For Python
20322.3 Michael Hudson implemented a similar scheme to determine when to
2033call the trace function, removing the need for \code{SET_LINENO}
2034entirely.
2035
Andrew M. Kuchling7a82b8c2002-11-04 20:17:24 +00002036It would be difficult to detect any resulting difference from Python
2037code, apart from a slight speed up when Python is run without
Michael W. Hudsondd32a912002-08-15 14:59:02 +00002038\programopt{-O}.
2039
2040C extensions that access the \member{f_lineno} field of frame objects
2041should instead call \code{PyCode_Addr2Line(f->f_code, f->f_lasti)}.
2042This will have the added effect of making the code work as desired
2043under ``python -O'' in earlier versions of Python.
2044
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00002045A nifty new feature is that trace functions can now assign to the
2046\member{f_lineno} attribute of frame objects, changing the line that
2047will be executed next. A \samp{jump} command has been added to the
2048\module{pdb} debugger taking advantage of this new feature.
2049(Implemented by Richie Hindle.)
Andrew M. Kuchling974ab9d2002-12-31 01:20:30 +00002050
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00002051\end{itemize}
2052
Andrew M. Kuchling187b1d82002-05-29 19:20:57 +00002053
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00002054%======================================================================
Andrew M. Kuchling950725f2002-08-06 01:40:48 +00002055\section{Porting to Python 2.3}
2056
Andrew M. Kuchlingf15fb292002-12-31 18:34:54 +00002057This section lists previously described changes that may require
2058changes to your code:
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00002059
2060\begin{itemize}
2061
2062\item \keyword{yield} is now always a keyword; if it's used as a
2063variable name in your code, a different name must be chosen.
2064
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00002065\item For strings \var{X} and \var{Y}, \code{\var{X} in \var{Y}} now works
2066if \var{X} is more than one character long.
2067
Andrew M. Kuchling495172c2002-11-20 13:50:15 +00002068\item The \function{int()} type constructor will now return a long
2069integer instead of raising an \exception{OverflowError} when a string
2070or floating-point number is too large to fit into an integer.
2071
Andrew M. Kuchlingb492fa92002-11-27 19:11:10 +00002072\item Calling Tcl methods through \module{_tkinter} no longer
2073returns only strings. Instead, if Tcl returns other objects those
2074objects are converted to their Python equivalent, if one exists, or
2075wrapped with a \class{_tkinter.Tcl_Obj} object if no Python equivalent
2076exists.
2077
Andrew M. Kuchling80fd7852003-02-06 15:14:04 +00002078\item Large octal and hex literals such as
20790xffffffff now trigger a \exception{FutureWarning} because currently
2080they're stored as 32-bit numbers and result in a negative value, but
2081in Python 2.4 they'll become positive long integers.
2082
Andrew M. Kuchling495172c2002-11-20 13:50:15 +00002083\item You can no longer disable assertions by assigning to \code{__debug__}.
2084
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00002085\item The Distutils \function{setup()} function has gained various new
Fred Drake5c4cf152002-11-13 14:59:06 +00002086keyword arguments such as \var{depends}. Old versions of the
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00002087Distutils will abort if passed unknown keywords. The fix is to check
2088for the presence of the new \function{get_distutil_options()} function
2089in your \file{setup.py} if you want to only support the new keywords
2090with a version of the Distutils that supports them:
2091
2092\begin{verbatim}
2093from distutils import core
2094
2095kw = {'sources': 'foo.c', ...}
2096if hasattr(core, 'get_distutil_options'):
2097 kw['depends'] = ['foo.h']
Fred Drake5c4cf152002-11-13 14:59:06 +00002098ext = Extension(**kw)
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00002099\end{verbatim}
2100
Andrew M. Kuchling495172c2002-11-20 13:50:15 +00002101\item Using \code{None} as a variable name will now result in a
2102\exception{SyntaxWarning} warning.
2103
2104\item Names of extension types defined by the modules included with
2105Python now contain the module and a \character{.} in front of the type
2106name.
2107
Andrew M. Kuchling8a61f492002-11-13 13:24:41 +00002108\end{itemize}
Andrew M. Kuchling950725f2002-08-06 01:40:48 +00002109
2110
2111%======================================================================
Fred Drake03e10312002-03-26 19:17:43 +00002112\section{Acknowledgements \label{acks}}
2113
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00002114The author would like to thank the following people for offering
2115suggestions, corrections and assistance with various drafts of this
Andrew M. Kuchlingb9ba4e62003-02-03 15:16:15 +00002116article: Simon Brunning, Michael Chermside, Andrew Dalke, Scott David
2117Daniels, Fred~L. Drake, Jr., Kelly Gerber, Raymond Hettinger, Michael
2118Hudson, Detlef Lannert, Martin von L\"owis, Andrew MacIntyre, Lalo
2119Martins, Gustavo Niemeyer, Neal Norwitz, Hans Nowak, Chris Reedy,
2120Vinay Sajip, Neil Schemenauer, Jason Tishler, Just van~Rossum.
Fred Drake03e10312002-03-26 19:17:43 +00002121
2122\end{document}