blob: 78120a108b4ba829aee88c4c762eeedddcb8f87f [file] [log] [blame]
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00001\documentclass{howto}
2
Andrew M. Kuchling3ad4e742000-09-27 01:33:41 +00003% $Id$
4
Andrew M. Kuchling730067e2000-06-30 01:44:05 +00005\title{What's New in Python 2.0}
Andrew M. Kuchlinga8d10782000-10-19 01:42:33 +00006\release{1.01}
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +00007\author{A.M. Kuchling and Moshe Zadka}
Andrew M. Kuchling10f9c072001-11-05 21:25:42 +00008\authoraddress{\email{akuchlin@mems-exchange.org}, \email{moshez@math.huji.ac.il} }
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00009\begin{document}
10\maketitle\tableofcontents
11
12\section{Introduction}
13
Andrew M. Kuchling91bae442002-04-18 02:18:27 +000014A new release of Python, version 2.0, was released on October 16, 2000. This
15article covers the exciting new features in 2.0, highlights some other
16useful changes, and points out a few incompatible changes that may require
Andrew M. Kuchling70ba3822000-07-01 00:13:30 +000017rewriting code.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +000018
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000019Python's development never completely stops between releases, and a
20steady flow of bug fixes and improvements are always being submitted.
21A host of minor fixes, a few optimizations, additional docstrings, and
Andrew M. Kuchling730067e2000-06-30 01:44:05 +000022better error messages went into 2.0; to list them all would be
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000023impossible, but they're certainly significant. Consult the
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +000024publicly-available CVS logs if you want to see the full list. This
25progress is due to the five developers working for
26PythonLabs are now getting paid to spend their days fixing bugs,
27and also due to the improved communication resulting
28from moving to SourceForge.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +000029
30% ======================================================================
Andrew M. Kuchling4d46d382000-09-06 17:58:49 +000031\section{What About Python 1.6?}
32
33Python 1.6 can be thought of as the Contractual Obligations Python
34release. After the core development team left CNRI in May 2000, CNRI
35requested that a 1.6 release be created, containing all the work on
36Python that had been performed at CNRI. Python 1.6 therefore
37represents the state of the CVS tree as of May 2000, with the most
38significant new feature being Unicode support. Development continued
39after May, of course, so the 1.6 tree received a few fixes to ensure
40that it's forward-compatible with Python 2.0. 1.6 is therefore part
41of Python's evolution, and not a side branch.
42
43So, should you take much interest in Python 1.6? Probably not. The
441.6final and 2.0beta1 releases were made on the same day (September 5,
452000), the plan being to finalize Python 2.0 within a month or so. If
46you have applications to maintain, there seems little point in
47breaking things by moving to 1.6, fixing them, and then having another
48round of breakage within a month by moving to 2.0; you're better off
49just going straight to 2.0. Most of the really interesting features
50described in this document are only in 2.0, because a lot of work was
51done between May and September.
52
53% ======================================================================
Andrew M. Kuchlingbe870dd2000-09-27 02:36:10 +000054\section{New Development Process}
55
56The most important change in Python 2.0 may not be to the code at all,
Andrew M. Kuchlingd44dc3c2000-10-04 12:40:44 +000057but to how Python is developed: in May 2000 the Python developers
58began using the tools made available by SourceForge for storing
59source code, tracking bug reports, and managing the queue of patch
60submissions. To report bugs or submit patches for Python 2.0, use the
61bug tracking and patch manager tools available from Python's project
62page, located at \url{http://sourceforge.net/projects/python/}.
Andrew M. Kuchlingbe870dd2000-09-27 02:36:10 +000063
Andrew M. Kuchlingd44dc3c2000-10-04 12:40:44 +000064The most important of the services now hosted at SourceForge is the
65Python CVS tree, the version-controlled repository containing the
66source code for Python. Previously, there were roughly 7 or so people
67who had write access to the CVS tree, and all patches had to be
68inspected and checked in by one of the people on this short list.
69Obviously, this wasn't very scalable. By moving the CVS tree to
70SourceForge, it became possible to grant write access to more people;
71as of September 2000 there were 27 people able to check in changes, a
72fourfold increase. This makes possible large-scale changes that
73wouldn't be attempted if they'd have to be filtered through the small
74group of core developers. For example, one day Peter Schneider-Kamp
75took it into his head to drop K\&R C compatibility and convert the C
76source for Python to ANSI C. After getting approval on the python-dev
77mailing list, he launched into a flurry of checkins that lasted about
78a week, other developers joined in to help, and the job was done. If
79there were only 5 people with write access, probably that task would
80have been viewed as ``nice, but not worth the time and effort needed''
81and it would never have gotten done.
Andrew M. Kuchlingbe870dd2000-09-27 02:36:10 +000082
Andrew M. Kuchlingd44dc3c2000-10-04 12:40:44 +000083The shift to using SourceForge's services has resulted in a remarkable
84increase in the speed of development. Patches now get submitted,
85commented on, revised by people other than the original submitter, and
86bounced back and forth between people until the patch is deemed worth
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +000087checking in. Bugs are tracked in one central location and can be
88assigned to a specific person for fixing, and we can count the number
89of open bugs to measure progress. This didn't come without a cost:
90developers now have more e-mail to deal with, more mailing lists to
91follow, and special tools had to be written for the new environment.
92For example, SourceForge sends default patch and bug notification
93e-mail messages that are completely unhelpful, so Ka-Ping Yee wrote an
94HTML screen-scraper that sends more useful messages.
Andrew M. Kuchlingbe870dd2000-09-27 02:36:10 +000095
96The ease of adding code caused a few initial growing pains, such as
97code was checked in before it was ready or without getting clear
98agreement from the developer group. The approval process that has
99emerged is somewhat similar to that used by the Apache group.
100Developers can vote +1, +0, -0, or -1 on a patch; +1 and -1 denote
101acceptance or rejection, while +0 and -0 mean the developer is mostly
102indifferent to the change, though with a slight positive or negative
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +0000103slant. The most significant change from the Apache model is that the
104voting is essentially advisory, letting Guido van Rossum, who has
105Benevolent Dictator For Life status, know what the general opinion is.
106He can still ignore the result of a vote, and approve or
107reject a change even if the community disagrees with him.
Andrew M. Kuchlingbe870dd2000-09-27 02:36:10 +0000108
109Producing an actual patch is the last step in adding a new feature,
110and is usually easy compared to the earlier task of coming up with a
111good design. Discussions of new features can often explode into
112lengthy mailing list threads, making the discussion hard to follow,
113and no one can read every posting to python-dev. Therefore, a
114relatively formal process has been set up to write Python Enhancement
115Proposals (PEPs), modelled on the Internet RFC process. PEPs are
116draft documents that describe a proposed new feature, and are
117continually revised until the community reaches a consensus, either
118accepting or rejecting the proposal. Quoting from the introduction to
119PEP 1, ``PEP Purpose and Guidelines'':
120
121\begin{quotation}
122 PEP stands for Python Enhancement Proposal. A PEP is a design
123 document providing information to the Python community, or
124 describing a new feature for Python. The PEP should provide a
125 concise technical specification of the feature and a rationale for
126 the feature.
127
128 We intend PEPs to be the primary mechanisms for proposing new
129 features, for collecting community input on an issue, and for
130 documenting the design decisions that have gone into Python. The
131 PEP author is responsible for building consensus within the
132 community and documenting dissenting opinions.
133\end{quotation}
134
135Read the rest of PEP 1 for the details of the PEP editorial process,
136style, and format. PEPs are kept in the Python CVS tree on
137SourceForge, though they're not part of the Python 2.0 distribution,
138and are also available in HTML form from
Fred Drakeb81fbad2002-04-03 02:52:50 +0000139\url{http://www.python.org/peps/}. As of September 2000,
Andrew M. Kuchlingbe870dd2000-09-27 02:36:10 +0000140there are 25 PEPS, ranging from PEP 201, ``Lockstep Iteration'', to
141PEP 225, ``Elementwise/Objectwise Operators''.
142
Andrew M. Kuchlingbe870dd2000-09-27 02:36:10 +0000143% ======================================================================
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000144\section{Unicode}
145
Andrew M. Kuchling730067e2000-06-30 01:44:05 +0000146The largest new feature in Python 2.0 is a new fundamental data type:
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000147Unicode strings. Unicode uses 16-bit numbers to represent characters
148instead of the 8-bit number used by ASCII, meaning that 65,536
149distinct characters can be supported.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000150
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000151The final interface for Unicode support was arrived at through
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000152countless often-stormy discussions on the python-dev mailing list, and
Andrew M. Kuchling62cdd962000-06-30 12:46:41 +0000153mostly implemented by Marc-Andr\'e Lemburg, based on a Unicode string
154type implementation by Fredrik Lundh. A detailed explanation of the
155interface is in the file \file{Misc/unicode.txt} in the Python source
156distribution; it's also available on the Web at
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000157\url{http://starship.python.net/crew/lemburg/unicode-proposal.txt}.
Andrew M. Kuchling6032c482000-10-12 02:37:14 +0000158This article will simply cover the most significant points about the Unicode
159interfaces.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000160
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000161In Python source code, Unicode strings are written as
162\code{u"string"}. Arbitrary Unicode characters can be written using a
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000163new escape sequence, \code{\e u\var{HHHH}}, where \var{HHHH} is a
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +00001644-digit hexadecimal number from 0000 to FFFF. The existing
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000165\code{\e x\var{HHHH}} escape sequence can also be used, and octal
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000166escapes can be used for characters up to U+01FF, which is represented
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000167by \code{\e 777}.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000168
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000169Unicode strings, just like regular strings, are an immutable sequence
Andrew M. Kuchling662d76e2000-06-25 14:32:48 +0000170type. They can be indexed and sliced, but not modified in place.
Andrew M. Kuchling62cdd962000-06-30 12:46:41 +0000171Unicode strings have an \method{encode( \optional{encoding} )} method
Andrew M. Kuchling662d76e2000-06-25 14:32:48 +0000172that returns an 8-bit string in the desired encoding. Encodings are
173named by strings, such as \code{'ascii'}, \code{'utf-8'},
174\code{'iso-8859-1'}, or whatever. A codec API is defined for
175implementing and registering new encodings that are then available
176throughout a Python program. If an encoding isn't specified, the
177default encoding is usually 7-bit ASCII, though it can be changed for
178your Python installation by calling the
Andrew M. Kuchlingc0328f02000-06-10 15:11:20 +0000179\function{sys.setdefaultencoding(\var{encoding})} function in a
Andrew M. Kuchling69db0e42000-06-28 02:16:00 +0000180customised version of \file{site.py}.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000181
182Combining 8-bit and Unicode strings always coerces to Unicode, using
183the default ASCII encoding; the result of \code{'a' + u'bc'} is
Andrew M. Kuchling7f6270d2000-06-09 02:48:18 +0000184\code{u'abc'}.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000185
186New built-in functions have been added, and existing built-ins
187modified to support Unicode:
188
189\begin{itemize}
190\item \code{unichr(\var{ch})} returns a Unicode string 1 character
191long, containing the character \var{ch}.
192
193\item \code{ord(\var{u})}, where \var{u} is a 1-character regular or Unicode string, returns the number of the character as an integer.
194
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000195\item \code{unicode(\var{string} \optional{, \var{encoding}}
196\optional{, \var{errors}} ) } creates a Unicode string from an 8-bit
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000197string. \code{encoding} is a string naming the encoding to use.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000198The \code{errors} parameter specifies the treatment of characters that
199are invalid for the current encoding; passing \code{'strict'} as the
200value causes an exception to be raised on any encoding error, while
201\code{'ignore'} causes errors to be silently ignored and
202\code{'replace'} uses U+FFFD, the official replacement character, in
203case of any problems.
204
Andrew M. Kuchling3ad4e742000-09-27 01:33:41 +0000205\item The \keyword{exec} statement, and various built-ins such as
206\code{eval()}, \code{getattr()}, and \code{setattr()} will also
207accept Unicode strings as well as regular strings. (It's possible
208that the process of fixing this missed some built-ins; if you find a
209built-in function that accepts strings but doesn't accept Unicode
210strings at all, please report it as a bug.)
211
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000212\end{itemize}
213
214A new module, \module{unicodedata}, provides an interface to Unicode
215character properties. For example, \code{unicodedata.category(u'A')}
216returns the 2-character string 'Lu', the 'L' denoting it's a letter,
217and 'u' meaning that it's uppercase.
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000218\code{u.bidirectional(u'\e x0660')} returns 'AN', meaning that U+0660 is
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000219an Arabic number.
220
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000221The \module{codecs} module contains functions to look up existing encodings
222and register new ones. Unless you want to implement a
223new encoding, you'll most often use the
224\function{codecs.lookup(\var{encoding})} function, which returns a
2254-element tuple: \code{(\var{encode_func},
226\var{decode_func}, \var{stream_reader}, \var{stream_writer})}.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000227
228\begin{itemize}
229\item \var{encode_func} is a function that takes a Unicode string, and
230returns a 2-tuple \code{(\var{string}, \var{length})}. \var{string}
231is an 8-bit string containing a portion (perhaps all) of the Unicode
Andrew M. Kuchling2d2dc9f2000-08-17 00:27:06 +0000232string converted into the given encoding, and \var{length} tells you
233how much of the Unicode string was converted.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000234
Andrew M. Kuchling118ee962000-09-27 01:01:18 +0000235\item \var{decode_func} is the opposite of \var{encode_func}, taking
236an 8-bit string and returning a 2-tuple \code{(\var{ustring},
237\var{length})}, consisting of the resulting Unicode string
238\var{ustring} and the integer \var{length} telling how much of the
Andrew M. Kuchling3ad4e742000-09-27 01:33:41 +00002398-bit string was consumed.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000240
241\item \var{stream_reader} is a class that supports decoding input from
242a stream. \var{stream_reader(\var{file_obj})} returns an object that
243supports the \method{read()}, \method{readline()}, and
244\method{readlines()} methods. These methods will all translate from
245the given encoding and return Unicode strings.
246
247\item \var{stream_writer}, similarly, is a class that supports
248encoding output to a stream. \var{stream_writer(\var{file_obj})}
Andrew M. Kuchling69db0e42000-06-28 02:16:00 +0000249returns an object that supports the \method{write()} and
250\method{writelines()} methods. These methods expect Unicode strings,
251translating them to the given encoding on output.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000252\end{itemize}
253
254For example, the following code writes a Unicode string into a file,
255encoding it as UTF-8:
256
257\begin{verbatim}
258import codecs
259
260unistr = u'\u0660\u2000ab ...'
261
262(UTF8_encode, UTF8_decode,
263 UTF8_streamreader, UTF8_streamwriter) = codecs.lookup('UTF-8')
264
265output = UTF8_streamwriter( open( '/tmp/output', 'wb') )
266output.write( unistr )
267output.close()
268\end{verbatim}
269
270The following code would then read UTF-8 input from the file:
271
272\begin{verbatim}
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000273input = UTF8_streamreader( open( '/tmp/output', 'rb') )
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000274print repr(input.read())
275input.close()
276\end{verbatim}
277
278Unicode-aware regular expressions are available through the
279\module{re} module, which has a new underlying implementation called
280SRE written by Fredrik Lundh of Secret Labs AB.
281
Andrew M. Kuchlingc0328f02000-06-10 15:11:20 +0000282A \code{-U} command line option was added which causes the Python
283compiler to interpret all string literals as Unicode string literals.
284This is intended to be used in testing and future-proofing your Python
285code, since some future version of Python may drop support for 8-bit
286strings and provide only Unicode strings.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000287
288% ======================================================================
Andrew M. Kuchling2d2dc9f2000-08-17 00:27:06 +0000289\section{List Comprehensions}
290
291Lists are a workhorse data type in Python, and many programs
292manipulate a list at some point. Two common operations on lists are
293to loop over them, and either pick out the elements that meet a
294certain criterion, or apply some function to each element. For
295example, given a list of strings, you might want to pull out all the
296strings containing a given substring, or strip off trailing whitespace
297from each line.
298
299The existing \function{map()} and \function{filter()} functions can be
300used for this purpose, but they require a function as one of their
301arguments. This is fine if there's an existing built-in function that
302can be passed directly, but if there isn't, you have to create a
303little function to do the required work, and Python's scoping rules
304make the result ugly if the little function needs additional
305information. Take the first example in the previous paragraph,
306finding all the strings in the list containing a given substring. You
307could write the following to do it:
308
309\begin{verbatim}
310# Given the list L, make a list of all strings
311# containing the substring S.
312sublist = filter( lambda s, substring=S:
313 string.find(s, substring) != -1,
314 L)
315\end{verbatim}
316
317Because of Python's scoping rules, a default argument is used so that
318the anonymous function created by the \keyword{lambda} statement knows
319what substring is being searched for. List comprehensions make this
320cleaner:
321
322\begin{verbatim}
323sublist = [ s for s in L if string.find(s, S) != -1 ]
324\end{verbatim}
325
326List comprehensions have the form:
327
328\begin{verbatim}
329[ expression for expr in sequence1
330 for expr2 in sequence2 ...
331 for exprN in sequenceN
332 if condition
333\end{verbatim}
334
335The \keyword{for}...\keyword{in} clauses contain the sequences to be
336iterated over. The sequences do not have to be the same length,
337because they are \emph{not} iterated over in parallel, but
338from left to right; this is explained more clearly in the following
339paragraphs. The elements of the generated list will be the successive
340values of \var{expression}. The final \keyword{if} clause is
341optional; if present, \var{expression} is only evaluated and added to
342the result if \var{condition} is true.
343
344To make the semantics very clear, a list comprehension is equivalent
345to the following Python code:
346
347\begin{verbatim}
348for expr1 in sequence1:
349 for expr2 in sequence2:
350 ...
351 for exprN in sequenceN:
352 if (condition):
353 # Append the value of
354 # the expression to the
355 # resulting list.
356\end{verbatim}
357
358This means that when there are \keyword{for}...\keyword{in} clauses,
359the resulting list will be equal to the product of the lengths of all
360the sequences. If you have two lists of length 3, the output list is
3619 elements long:
362
363\begin{verbatim}
364seq1 = 'abc'
365seq2 = (1,2,3)
366>>> [ (x,y) for x in seq1 for y in seq2]
367[('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2), ('b', 3), ('c', 1),
368('c', 2), ('c', 3)]
369\end{verbatim}
370
371To avoid introducing an ambiguity into Python's grammar, if
372\var{expression} is creating a tuple, it must be surrounded with
373parentheses. The first list comprehension below is a syntax error,
374while the second one is correct:
375
376\begin{verbatim}
377# Syntax error
378[ x,y for x in seq1 for y in seq2]
379# Correct
380[ (x,y) for x in seq1 for y in seq2]
381\end{verbatim}
382
Andrew M. Kuchling2d2dc9f2000-08-17 00:27:06 +0000383The idea of list comprehensions originally comes from the functional
384programming language Haskell (\url{http://www.haskell.org}). Greg
385Ewing argued most effectively for adding them to Python and wrote the
386initial list comprehension patch, which was then discussed for a
387seemingly endless time on the python-dev mailing list and kept
388up-to-date by Skip Montanaro.
389
Andrew M. Kuchling2d2dc9f2000-08-17 00:27:06 +0000390% ======================================================================
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000391\section{Augmented Assignment}
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000392
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000393Augmented assignment operators, another long-requested feature, have
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000394been added to Python 2.0. Augmented assignment operators include
395\code{+=}, \code{-=}, \code{*=}, and so forth. For example, the
396statement \code{a += 2} increments the value of the variable
397\code{a} by 2, equivalent to the slightly lengthier \code{a = a + 2}.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000398
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000399The full list of supported assignment operators is \code{+=},
400\code{-=}, \code{*=}, \code{/=}, \code{\%=}, \code{**=}, \code{\&=},
Andrew M. Kuchling3cdb5762000-08-30 12:55:42 +0000401\code{|=}, \verb|^=|, \code{>>=}, and \code{<<=}. Python classes can
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000402override the augmented assignment operators by defining methods named
403\method{__iadd__}, \method{__isub__}, etc. For example, the following
404\class{Number} class stores a number and supports using += to create a
405new instance with an incremented value.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000406
407\begin{verbatim}
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000408class Number:
409 def __init__(self, value):
410 self.value = value
411 def __iadd__(self, increment):
412 return Number( self.value + increment)
413
414n = Number(5)
415n += 3
416print n.value
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000417\end{verbatim}
418
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000419The \method{__iadd__} special method is called with the value of the
420increment, and should return a new instance with an appropriately
421modified value; this return value is bound as the new value of the
422variable on the left-hand side.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000423
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000424Augmented assignment operators were first introduced in the C
425programming language, and most C-derived languages, such as
426\program{awk}, C++, Java, Perl, and PHP also support them. The augmented
427assignment patch was implemented by Thomas Wouters.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000428
429% ======================================================================
430\section{String Methods}
431
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000432Until now string-manipulation functionality was in the \module{string}
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000433module, which was usually a front-end for the \module{strop}
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000434module written in C. The addition of Unicode posed a difficulty for
435the \module{strop} module, because the functions would all need to be
436rewritten in order to accept either 8-bit or Unicode strings. For
437functions such as \function{string.replace()}, which takes 3 string
438arguments, that means eight possible permutations, and correspondingly
439complicated code.
440
Andrew M. Kuchling730067e2000-06-30 01:44:05 +0000441Instead, Python 2.0 pushes the problem onto the string type, making
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000442string manipulation functionality available through methods on both
4438-bit strings and Unicode strings.
444
445\begin{verbatim}
446>>> 'andrew'.capitalize()
447'Andrew'
448>>> 'hostname'.replace('os', 'linux')
449'hlinuxtname'
450>>> 'moshe'.find('sh')
4512
452\end{verbatim}
453
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000454One thing that hasn't changed, a noteworthy April Fools' joke
455notwithstanding, is that Python strings are immutable. Thus, the
456string methods return new strings, and do not modify the string on
457which they operate.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000458
459The old \module{string} module is still around for backwards
460compatibility, but it mostly acts as a front-end to the new string
461methods.
462
Andrew M. Kuchling730067e2000-06-30 01:44:05 +0000463Two methods which have no parallel in pre-2.0 versions, although they
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000464did exist in JPython for quite some time, are \method{startswith()}
465and \method{endswith}. \code{s.startswith(t)} is equivalent to \code{s[:len(t)]
466== t}, while \code{s.endswith(t)} is equivalent to \code{s[-len(t):] == t}.
467
Andrew M. Kuchlingfed4f1e2000-07-01 12:33:43 +0000468One other method which deserves special mention is \method{join}. The
469\method{join} method of a string receives one parameter, a sequence of
470strings, and is equivalent to the \function{string.join} function from
471the old \module{string} module, with the arguments reversed. In other
472words, \code{s.join(seq)} is equivalent to the old
473\code{string.join(seq, s)}.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000474
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000475% ======================================================================
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +0000476\section{Garbage Collection of Cycles}
Andrew M. Kuchling35e8afb2000-07-08 12:06:31 +0000477
478The C implementation of Python uses reference counting to implement
479garbage collection. Every Python object maintains a count of the
480number of references pointing to itself, and adjusts the count as
481references are created or destroyed. Once the reference count reaches
482zero, the object is no longer accessible, since you need to have a
483reference to an object to access it, and if the count is zero, no
484references exist any longer.
485
486Reference counting has some pleasant properties: it's easy to
487understand and implement, and the resulting implementation is
488portable, fairly fast, and reacts well with other libraries that
489implement their own memory handling schemes. The major problem with
490reference counting is that it sometimes doesn't realise that objects
491are no longer accessible, resulting in a memory leak. This happens
492when there are cycles of references.
493
494Consider the simplest possible cycle,
495a class instance which has a reference to itself:
496
497\begin{verbatim}
498instance = SomeClass()
499instance.myself = instance
500\end{verbatim}
501
502After the above two lines of code have been executed, the reference
503count of \code{instance} is 2; one reference is from the variable
504named \samp{'instance'}, and the other is from the \samp{myself}
505attribute of the instance.
506
507If the next line of code is \code{del instance}, what happens? The
508reference count of \code{instance} is decreased by 1, so it has a
509reference count of 1; the reference in the \samp{myself} attribute
510still exists. Yet the instance is no longer accessible through Python
511code, and it could be deleted. Several objects can participate in a
512cycle if they have references to each other, causing all of the
513objects to be leaked.
514
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +0000515Python 2.0 fixes this problem by periodically executing a cycle
516detection algorithm which looks for inaccessible cycles and deletes
517the objects involved. A new \module{gc} module provides functions to
518perform a garbage collection, obtain debugging statistics, and tuning
519the collector's parameters.
Andrew M. Kuchling35e8afb2000-07-08 12:06:31 +0000520
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +0000521Running the cycle detection algorithm takes some time, and therefore
522will result in some additional overhead. It is hoped that after we've
523gotten experience with the cycle collection from using 2.0, Python 2.1
524will be able to minimize the overhead with careful tuning. It's not
525yet obvious how much performance is lost, because benchmarking this is
526tricky and depends crucially on how often the program creates and
527destroys objects. The detection of cycles can be disabled when Python
528is compiled, if you can't afford even a tiny speed penalty or suspect
529that the cycle collection is buggy, by specifying the
530\samp{--without-cycle-gc} switch when running the \file{configure}
531script.
Andrew M. Kuchling35e8afb2000-07-08 12:06:31 +0000532
533Several people tackled this problem and contributed to a solution. An
534early implementation of the cycle detection approach was written by
535Toby Kelsey. The current algorithm was suggested by Eric Tiedemann
536during a visit to CNRI, and Guido van Rossum and Neil Schemenauer
537wrote two different implementations, which were later integrated by
538Neil. Lots of other people offered suggestions along the way; the
539March 2000 archives of the python-dev mailing list contain most of the
540relevant discussion, especially in the threads titled ``Reference
541cycle collection for Python'' and ``Finalization again''.
542
Andrew M. Kuchling35e8afb2000-07-08 12:06:31 +0000543% ======================================================================
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000544\section{Other Core Changes}
Andrew M. Kuchling35e8afb2000-07-08 12:06:31 +0000545
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000546Various minor changes have been made to Python's syntax and built-in
547functions. None of the changes are very far-reaching, but they're
548handy conveniences.
549
550\subsection{Minor Language Changes}
551
552A new syntax makes it more convenient to call a given function
553with a tuple of arguments and/or a dictionary of keyword arguments.
554In Python 1.5 and earlier, you'd use the \function{apply()}
555built-in function: \code{apply(f, \var{args}, \var{kw})} calls the
556function \function{f()} with the argument tuple \var{args} and the
557keyword arguments in the dictionary \var{kw}. \function{apply()}
558is the same in 2.0, but thanks to a patch from
559Greg Ewing, \code{f(*\var{args}, **\var{kw})} as a shorter
560and clearer way to achieve the same effect. This syntax is
561symmetrical with the syntax for defining functions:
562
563\begin{verbatim}
564def f(*args, **kw):
565 # args is a tuple of positional args,
566 # kw is a dictionary of keyword args
567 ...
568\end{verbatim}
569
570The \keyword{print} statement can now have its output directed to a
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000571file-like object by following the \keyword{print} with
572\verb|>> file|, similar to the redirection operator in Unix shells.
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000573Previously you'd either have to use the \method{write()} method of the
574file-like object, which lacks the convenience and simplicity of
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000575\keyword{print}, or you could assign a new value to
576\code{sys.stdout} and then restore the old value. For sending output to standard error,
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000577it's much easier to write this:
578
579\begin{verbatim}
580print >> sys.stderr, "Warning: action field not supplied"
581\end{verbatim}
582
583Modules can now be renamed on importing them, using the syntax
584\code{import \var{module} as \var{name}} or \code{from \var{module}
585import \var{name} as \var{othername}}. The patch was submitted by
586Thomas Wouters.
587
588A new format style is available when using the \code{\%} operator;
589'\%r' will insert the \function{repr()} of its argument. This was
590also added from symmetry considerations, this time for symmetry with
591the existing '\%s' format style, which inserts the \function{str()} of
592its argument. For example, \code{'\%r \%s' \% ('abc', 'abc')} returns a
593string containing \verb|'abc' abc|.
594
595Previously there was no way to implement a class that overrode
596Python's built-in \keyword{in} operator and implemented a custom
597version. \code{\var{obj} in \var{seq}} returns true if \var{obj} is
598present in the sequence \var{seq}; Python computes this by simply
599trying every index of the sequence until either \var{obj} is found or
600an \exception{IndexError} is encountered. Moshe Zadka contributed a
601patch which adds a \method{__contains__} magic method for providing a
602custom implementation for \keyword{in}. Additionally, new built-in
603objects written in C can define what \keyword{in} means for them via a
604new slot in the sequence protocol.
605
606Earlier versions of Python used a recursive algorithm for deleting
607objects. Deeply nested data structures could cause the interpreter to
608fill up the C stack and crash; Christian Tismer rewrote the deletion
609logic to fix this problem. On a related note, comparing recursive
610objects recursed infinitely and crashed; Jeremy Hylton rewrote the
611code to no longer crash, producing a useful result instead. For
612example, after this code:
613
614\begin{verbatim}
615a = []
616b = []
617a.append(a)
618b.append(b)
619\end{verbatim}
620
621The comparison \code{a==b} returns true, because the two recursive
Andrew M. Kuchling6032c482000-10-12 02:37:14 +0000622data structures are isomorphic. See the thread ``trashcan
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000623and PR\#7'' in the April 2000 archives of the python-dev mailing list
624for the discussion leading up to this implementation, and some useful
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +0000625relevant links.
Andrew M. Kuchling6032c482000-10-12 02:37:14 +0000626% Starting URL:
627% http://www.python.org/pipermail/python-dev/2000-April/004834.html
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000628
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +0000629Note that comparisons can now also raise exceptions. In earlier
630versions of Python, a comparison operation such as \code{cmp(a,b)}
631would always produce an answer, even if a user-defined
632\method{__cmp__} method encountered an error, since the resulting
633exception would simply be silently swallowed.
634
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000635Work has been done on porting Python to 64-bit Windows on the Itanium
636processor, mostly by Trent Mick of ActiveState. (Confusingly,
637\code{sys.platform} is still \code{'win32'} on Win64 because it seems
638that for ease of porting, MS Visual C++ treats code as 32 bit on Itanium.)
639PythonWin also supports Windows CE; see the Python CE page at
640\url{http://starship.python.net/crew/mhammond/ce/} for more
641information.
642
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +0000643Another new platform is Darwin/MacOS X; inital support for it is in
644Python 2.0. Dynamic loading works, if you specify ``configure
645--with-dyld --with-suffix=.x''. Consult the README in the Python
646source distribution for more instructions.
647
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000648An attempt has been made to alleviate one of Python's warts, the
649often-confusing \exception{NameError} exception when code refers to a
650local variable before the variable has been assigned a value. For
651example, the following code raises an exception on the \keyword{print}
652statement in both 1.5.2 and 2.0; in 1.5.2 a \exception{NameError}
653exception is raised, while 2.0 raises a new
654\exception{UnboundLocalError} exception.
655\exception{UnboundLocalError} is a subclass of \exception{NameError},
656so any existing code that expects \exception{NameError} to be raised
657should still work.
658
659\begin{verbatim}
660def f():
661 print "i=",i
662 i = i + 1
663f()
664\end{verbatim}
665
Andrew M. Kuchling4d46d382000-09-06 17:58:49 +0000666Two new exceptions, \exception{TabError} and
667\exception{IndentationError}, have been introduced. They're both
668subclasses of \exception{SyntaxError}, and are raised when Python code
669is found to be improperly indented.
670
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000671\subsection{Changes to Built-in Functions}
672
673A new built-in, \function{zip(\var{seq1}, \var{seq2}, ...)}, has been
674added. \function{zip()} returns a list of tuples where each tuple
675contains the i-th element from each of the argument sequences. The
676difference between \function{zip()} and \code{map(None, \var{seq1},
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000677\var{seq2})} is that \function{map()} pads the sequences with
678\code{None} if the sequences aren't all of the same length, while
679\function{zip()} truncates the returned list to the length of the
680shortest argument sequence.
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000681
682The \function{int()} and \function{long()} functions now accept an
683optional ``base'' parameter when the first argument is a string.
684\code{int('123', 10)} returns 123, while \code{int('123', 16)} returns
685291. \code{int(123, 16)} raises a \exception{TypeError} exception
686with the message ``can't convert non-string with explicit base''.
687
688A new variable holding more detailed version information has been
689added to the \module{sys} module. \code{sys.version_info} is a tuple
690\code{(\var{major}, \var{minor}, \var{micro}, \var{level},
691\var{serial})} For example, in a hypothetical 2.0.1beta1,
692\code{sys.version_info} would be \code{(2, 0, 1, 'beta', 1)}.
693\var{level} is a string such as \code{"alpha"}, \code{"beta"}, or
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000694\code{"final"} for a final release.
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000695
696Dictionaries have an odd new method, \method{setdefault(\var{key},
697\var{default})}, which behaves similarly to the existing
698\method{get()} method. However, if the key is missing,
699\method{setdefault()} both returns the value of \var{default} as
700\method{get()} would do, and also inserts it into the dictionary as
701the value for \var{key}. Thus, the following lines of code:
702
703\begin{verbatim}
704if dict.has_key( key ): return dict[key]
705else:
706 dict[key] = []
707 return dict[key]
708\end{verbatim}
709
710can be reduced to a single \code{return dict.setdefault(key, [])} statement.
711
Andrew M. Kuchling4d46d382000-09-06 17:58:49 +0000712The interpreter sets a maximum recursion depth in order to catch
713runaway recursion before filling the C stack and causing a core dump
714or GPF.. Previously this limit was fixed when you compiled Python,
715but in 2.0 the maximum recursion depth can be read and modified using
716\function{sys.getrecursionlimit} and \function{sys.setrecursionlimit}.
717The default value is 1000, and a rough maximum value for a given
718platform can be found by running a new script,
719\file{Misc/find_recursionlimit.py}.
Andrew M. Kuchling35e8afb2000-07-08 12:06:31 +0000720
721% ======================================================================
Andrew M. Kuchling730067e2000-06-30 01:44:05 +0000722\section{Porting to 2.0}
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000723
724New Python releases try hard to be compatible with previous releases,
725and the record has been pretty good. However, some changes are
Andrew M. Kuchling4d46d382000-09-06 17:58:49 +0000726considered useful enough, usually because they fix initial design decisions that
727turned out to be actively mistaken, that breaking backward compatibility
Andrew M. Kuchling730067e2000-06-30 01:44:05 +0000728can't always be avoided. This section lists the changes in Python 2.0
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000729that may cause old Python code to break.
730
731The change which will probably break the most code is tightening up
732the arguments accepted by some methods. Some methods would take
733multiple arguments and treat them as a tuple, particularly various
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +0000734list methods such as \method{.append()} and \method{.insert()}.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000735In earlier versions of Python, if \code{L} is a list, \code{L.append(
Andrew M. Kuchling730067e2000-06-30 01:44:05 +00007361,2 )} appends the tuple \code{(1,2)} to the list. In Python 2.0 this
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000737causes a \exception{TypeError} exception to be raised, with the
738message: 'append requires exactly 1 argument; 2 given'. The fix is to
739simply add an extra set of parentheses to pass both values as a tuple:
740\code{L.append( (1,2) )}.
741
742The earlier versions of these methods were more forgiving because they
743used an old function in Python's C interface to parse their arguments;
Andrew M. Kuchling730067e2000-06-30 01:44:05 +00007442.0 modernizes them to use \function{PyArg_ParseTuple}, the current
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000745argument parsing function, which provides more helpful error messages
746and treats multi-argument calls as errors. If you absolutely must use
Andrew M. Kuchling730067e2000-06-30 01:44:05 +00007472.0 but can't fix your code, you can edit \file{Objects/listobject.c}
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000748and define the preprocessor symbol \code{NO_STRICT_LIST_APPEND} to
749preserve the old behaviour; this isn't recommended.
750
751Some of the functions in the \module{socket} module are still
752forgiving in this way. For example, \function{socket.connect(
753('hostname', 25) )} is the correct form, passing a tuple representing
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +0000754an IP address, but \function{socket.connect( 'hostname', 25 )} also
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000755works. \function{socket.connect_ex()} and \function{socket.bind()} are
Andrew M. Kuchling730067e2000-06-30 01:44:05 +0000756similarly easy-going. 2.0alpha1 tightened these functions up, but
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000757because the documentation actually used the erroneous multiple
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +0000758argument form, many people wrote code which would break with the
759stricter checking. GvR backed out the changes in the face of public
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000760reaction, so for the \module{socket} module, the documentation was
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +0000761fixed and the multiple argument form is simply marked as deprecated;
762it \emph{will} be tightened up again in a future Python version.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000763
Andrew M. Kuchling4d46d382000-09-06 17:58:49 +0000764The \code{\e x} escape in string literals now takes exactly 2 hex
765digits. Previously it would consume all the hex digits following the
766'x' and take the lowest 8 bits of the result, so \code{\e x123456} was
767equivalent to \code{\e x56}.
768
769The \exception{AttributeError} exception has a more friendly error message,
770whose text will be something like \code{'Spam' instance has no attribute 'eggs'}.
771Previously the error message was just the missing attribute name \code{eggs}, and
772code written to take advantage of this fact will break in 2.0.
773
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000774Some work has been done to make integers and long integers a bit more
775interchangeable. In 1.5.2, large-file support was added for Solaris,
776to allow reading files larger than 2Gb; this made the \method{tell()}
777method of file objects return a long integer instead of a regular
778integer. Some code would subtract two file offsets and attempt to use
779the result to multiply a sequence or slice a string, but this raised a
Andrew M. Kuchling730067e2000-06-30 01:44:05 +0000780\exception{TypeError}. In 2.0, long integers can be used to multiply
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +0000781or slice a sequence, and it'll behave as you'd intuitively expect it
782to; \code{3L * 'abc'} produces 'abcabcabc', and \code{
783(0,1,2,3)[2L:4L]} produces (2,3). Long integers can also be used in
Andrew M. Kuchling3ad4e742000-09-27 01:33:41 +0000784various contexts where previously only integers were accepted, such
785as in the \method{seek()} method of file objects, and in the formats
786supported by the \verb|%| operator (\verb|%d|, \verb|%i|, \verb|%x|,
787etc.). For example, \code{"\%d" \% 2L**64} will produce the string
788\samp{18446744073709551616}.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000789
790The subtlest long integer change of all is that the \function{str()}
791of a long integer no longer has a trailing 'L' character, though
792\function{repr()} still includes it. The 'L' annoyed many people who
793wanted to print long integers that looked just like regular integers,
794since they had to go out of their way to chop off the character. This
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000795is no longer a problem in 2.0, but code which does \code{str(longval)[:-1]} and assumes the 'L' is there, will now lose
796the final digit.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000797
798Taking the \function{repr()} of a float now uses a different
799formatting precision than \function{str()}. \function{repr()} uses
Andrew M. Kuchling662d76e2000-06-25 14:32:48 +0000800\code{\%.17g} format string for C's \function{sprintf()}, while
801\function{str()} uses \code{\%.12g} as before. The effect is that
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000802\function{repr()} may occasionally show more decimal places than
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000803\function{str()}, for certain numbers.
Andrew M. Kuchlinga5bbb002000-06-10 02:41:46 +0000804For example, the number 8.1 can't be represented exactly in binary, so
805\code{repr(8.1)} is \code{'8.0999999999999996'}, while str(8.1) is
806\code{'8.1'}.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000807
Andrew M. Kuchling730067e2000-06-30 01:44:05 +0000808The \code{-X} command-line option, which turned all standard
Andrew M. Kuchling62cdd962000-06-30 12:46:41 +0000809exceptions into strings instead of classes, has been removed; the
810standard exceptions will now always be classes. The
811\module{exceptions} module containing the standard exceptions was
812translated from Python to a built-in C module, written by Barry Warsaw
813and Fredrik Lundh.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000814
Andrew M. Kuchling791b3662000-07-01 15:04:18 +0000815% Commented out for now -- I don't think anyone will care.
816%The pattern and match objects provided by SRE are C types, not Python
817%class instances as in 1.5. This means you can no longer inherit from
818%\class{RegexObject} or \class{MatchObject}, but that shouldn't be much
819%of a problem since no one should have been doing that in the first
820%place.
821
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000822% ======================================================================
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000823\section{Extending/Embedding Changes}
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000824
825Some of the changes are under the covers, and will only be apparent to
Andrew M. Kuchling8357c4c2000-07-01 00:14:43 +0000826people writing C extension modules or embedding a Python interpreter
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000827in a larger application. If you aren't dealing with Python's C API,
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000828you can safely skip this section.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000829
Andrew M. Kuchlinga5bbb002000-06-10 02:41:46 +0000830The version number of the Python C API was incremented, so C
831extensions compiled for 1.5.2 must be recompiled in order to work with
Andrew M. Kuchlinga8d10782000-10-19 01:42:33 +00008322.0. On Windows, it's not possible for Python 2.0 to import a third
833party extension built for Python 1.5.x due to how Windows DLLs work,
834so Python will raise an exception and the import will fail.
Andrew M. Kuchlinga5bbb002000-06-10 02:41:46 +0000835
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000836Users of Jim Fulton's ExtensionClass module will be pleased to find
837out that hooks have been added so that ExtensionClasses are now
838supported by \function{isinstance()} and \function{issubclass()}.
839This means you no longer have to remember to write code such as
840\code{if type(obj) == myExtensionClass}, but can use the more natural
841\code{if isinstance(obj, myExtensionClass)}.
842
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000843The \file{Python/importdl.c} file, which was a mass of \#ifdefs to
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000844support dynamic loading on many different platforms, was cleaned up
Andrew M. Kuchling69db0e42000-06-28 02:16:00 +0000845and reorganised by Greg Stein. \file{importdl.c} is now quite small,
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000846and platform-specific code has been moved into a bunch of
Andrew M. Kuchlingb9fb1f22000-08-04 12:40:35 +0000847\file{Python/dynload_*.c} files. Another cleanup: there were also a
848number of \file{my*.h} files in the Include/ directory that held
849various portability hacks; they've been merged into a single file,
850\file{Include/pyport.h}.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000851
852Vladimir Marangozov's long-awaited malloc restructuring was completed,
853to make it easy to have the Python interpreter use a custom allocator
854instead of C's standard \function{malloc()}. For documentation, read
Andrew M. Kuchling2d2dc9f2000-08-17 00:27:06 +0000855the comments in \file{Include/pymem.h} and
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000856\file{Include/objimpl.h}. For the lengthy discussions during which
857the interface was hammered out, see the Web archives of the 'patches'
858and 'python-dev' lists at python.org.
859
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +0000860Recent versions of the GUSI development environment for MacOS support
861POSIX threads. Therefore, Python's POSIX threading support now works
862on the Macintosh. Threading support using the user-space GNU \texttt{pth}
863library was also contributed.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000864
865Threading support on Windows was enhanced, too. Windows supports
866thread locks that use kernel objects only in case of contention; in
867the common case when there's no contention, they use simpler functions
868which are an order of magnitude faster. A threaded version of Python
Andrew M. Kuchling730067e2000-06-30 01:44:05 +00008691.5.2 on NT is twice as slow as an unthreaded version; with the 2.0
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000870changes, the difference is only 10\%. These improvements were
871contributed by Yakov Markovitch.
872
Andrew M. Kuchling08d87c62000-07-09 15:05:15 +0000873Python 2.0's source now uses only ANSI C prototypes, so compiling Python now
874requires an ANSI C compiler, and can no longer be done using a compiler that
875only supports K\&R C.
876
Andrew M. Kuchling4d46d382000-09-06 17:58:49 +0000877Previously the Python virtual machine used 16-bit numbers in its
878bytecode, limiting the size of source files. In particular, this
879affected the maximum size of literal lists and dictionaries in Python
Andrew M. Kuchling3ad4e742000-09-27 01:33:41 +0000880source; occasionally people who are generating Python code would run
881into this limit. A patch by Charles G. Waldman raises the limit from
882\verb|2^16| to \verb|2^{32}|.
Andrew M. Kuchling4d46d382000-09-06 17:58:49 +0000883
Andrew M. Kuchling3ad4e742000-09-27 01:33:41 +0000884Three new convenience functions intended for adding constants to a
885module's dictionary at module initialization time were added:
886\function{PyModule_AddObject()}, \function{PyModule_AddIntConstant()},
887and \function{PyModule_AddStringConstant()}. Each of these functions
888takes a module object, a null-terminated C string containing the name
889to be added, and a third argument for the value to be assigned to the
890name. This third argument is, respectively, a Python object, a C
891long, or a C string.
892
893A wrapper API was added for Unix-style signal handlers.
894\function{PyOS_getsig()} gets a signal handler and
895\function{PyOS_setsig()} will set a new handler.
Andrew M. Kuchling4d46d382000-09-06 17:58:49 +0000896
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000897% ======================================================================
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000898\section{Distutils: Making Modules Easy to Install}
899
900Before Python 2.0, installing modules was a tedious affair -- there
901was no way to figure out automatically where Python is installed, or
902what compiler options to use for extension modules. Software authors
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +0000903had to go through an arduous ritual of editing Makefiles and
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000904configuration files, which only really work on Unix and leave Windows
Andrew M. Kuchling3ad4e742000-09-27 01:33:41 +0000905and MacOS unsupported. Python users faced wildly differing
906installation instructions which varied between different extension
907packages, which made adminstering a Python installation something of a
908chore.
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000909
910The SIG for distribution utilities, shepherded by Greg Ward, has
911created the Distutils, a system to make package installation much
912easier. They form the \module{distutils} package, a new part of
913Python's standard library. In the best case, installing a Python
914module from source will require the same steps: first you simply mean
915unpack the tarball or zip archive, and the run ``\code{python setup.py
916install}''. The platform will be automatically detected, the compiler
917will be recognized, C extension modules will be compiled, and the
918distribution installed into the proper directory. Optional
919command-line arguments provide more control over the installation
920process, the distutils package offers many places to override defaults
921-- separating the build from the install, building or installing in
922non-default directories, and more.
923
924In order to use the Distutils, you need to write a \file{setup.py}
925script. For the simple case, when the software contains only .py
926files, a minimal \file{setup.py} can be just a few lines long:
927
928\begin{verbatim}
929from distutils.core import setup
930setup (name = "foo", version = "1.0",
931 py_modules = ["module1", "module2"])
932\end{verbatim}
933
934The \file{setup.py} file isn't much more complicated if the software
935consists of a few packages:
936
937\begin{verbatim}
938from distutils.core import setup
939setup (name = "foo", version = "1.0",
940 packages = ["package", "package.subpackage"])
941\end{verbatim}
942
943A C extension can be the most complicated case; here's an example taken from
944the PyXML package:
945
946
947\begin{verbatim}
948from distutils.core import setup, Extension
949
950expat_extension = Extension('xml.parsers.pyexpat',
951 define_macros = [('XML_NS', None)],
952 include_dirs = [ 'extensions/expat/xmltok',
953 'extensions/expat/xmlparse' ],
954 sources = [ 'extensions/pyexpat.c',
955 'extensions/expat/xmltok/xmltok.c',
956 'extensions/expat/xmltok/xmlrole.c',
957 ]
958 )
959setup (name = "PyXML", version = "0.5.4",
960 ext_modules =[ expat_extension ] )
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000961\end{verbatim}
962
963The Distutils can also take care of creating source and binary
964distributions. The ``sdist'' command, run by ``\code{python setup.py
965sdist}', builds a source distribution such as \file{foo-1.0.tar.gz}.
966Adding new commands isn't difficult, ``bdist_rpm'' and
967``bdist_wininst'' commands have already been contributed to create an
968RPM distribution and a Windows installer for the software,
969respectively. Commands to create other distribution formats such as
970Debian packages and Solaris \file{.pkg} files are in various stages of
971development.
972
973All this is documented in a new manual, \textit{Distributing Python
974Modules}, that joins the basic set of Python documentation.
975
Fred Drake7486c6b2000-10-12 02:49:12 +0000976% ======================================================================
Andrew M. Kuchling6032c482000-10-12 02:37:14 +0000977\section{XML Modules}
Andrew M. Kuchling43737642000-08-30 00:51:02 +0000978
Andrew M. Kuchling6032c482000-10-12 02:37:14 +0000979Python 1.5.2 included a simple XML parser in the form of the
980\module{xmllib} module, contributed by Sjoerd Mullender. Since
9811.5.2's release, two different interfaces for processing XML have
982become common: SAX2 (version 2 of the Simple API for XML) provides an
983event-driven interface with some similarities to \module{xmllib}, and
984the DOM (Document Object Model) provides a tree-based interface,
985transforming an XML document into a tree of nodes that can be
986traversed and modified. Python 2.0 includes a SAX2 interface and a
987stripped-down DOM interface as part of the \module{xml} package.
988Here we will give a brief overview of these new interfaces; consult
989the Python documentation or the source code for complete details.
990The Python XML SIG is also working on improved documentation.
991
992\subsection{SAX2 Support}
993
994SAX defines an event-driven interface for parsing XML. To use SAX,
995you must write a SAX handler class. Handler classes inherit from
996various classes provided by SAX, and override various methods that
997will then be called by the XML parser. For example, the
998\method{startElement} and \method{endElement} methods are called for
999every starting and end tag encountered by the parser, the
1000\method{characters()} method is called for every chunk of character
1001data, and so forth.
1002
1003The advantage of the event-driven approach is that that the whole
1004document doesn't have to be resident in memory at any one time, which
1005matters if you are processing really huge documents. However, writing
1006the SAX handler class can get very complicated if you're trying to
1007modify the document structure in some elaborate way.
1008
1009For example, this little example program defines a handler that prints
1010a message for every starting and ending tag, and then parses the file
1011\file{hamlet.xml} using it:
1012
1013\begin{verbatim}
1014from xml import sax
1015
1016class SimpleHandler(sax.ContentHandler):
1017 def startElement(self, name, attrs):
1018 print 'Start of element:', name, attrs.keys()
1019
1020 def endElement(self, name):
1021 print 'End of element:', name
1022
1023# Create a parser object
1024parser = sax.make_parser()
1025
1026# Tell it what handler to use
1027handler = SimpleHandler()
1028parser.setContentHandler( handler )
1029
1030# Parse a file!
1031parser.parse( 'hamlet.xml' )
1032\end{verbatim}
1033
1034For more information, consult the Python documentation, or the XML
1035HOWTO at \url{http://www.python.org/doc/howto/xml/}.
1036
1037\subsection{DOM Support}
1038
1039The Document Object Model is a tree-based representation for an XML
1040document. A top-level \class{Document} instance is the root of the
1041tree, and has a single child which is the top-level \class{Element}
1042instance. This \class{Element} has children nodes representing
1043character data and any sub-elements, which may have further children
1044of their own, and so forth. Using the DOM you can traverse the
1045resulting tree any way you like, access element and attribute values,
1046insert and delete nodes, and convert the tree back into XML.
1047
1048The DOM is useful for modifying XML documents, because you can create
1049a DOM tree, modify it by adding new nodes or rearranging subtrees, and
1050then produce a new XML document as output. You can also construct a
1051DOM tree manually and convert it to XML, which can be a more flexible
1052way of producing XML output than simply writing
1053\code{<tag1>}...\code{</tag1>} to a file.
1054
1055The DOM implementation included with Python lives in the
1056\module{xml.dom.minidom} module. It's a lightweight implementation of
1057the Level 1 DOM with support for XML namespaces. The
1058\function{parse()} and \function{parseString()} convenience
1059functions are provided for generating a DOM tree:
1060
1061\begin{verbatim}
1062from xml.dom import minidom
1063doc = minidom.parse('hamlet.xml')
1064\end{verbatim}
1065
1066\code{doc} is a \class{Document} instance. \class{Document}, like all
1067the other DOM classes such as \class{Element} and \class{Text}, is a
1068subclass of the \class{Node} base class. All the nodes in a DOM tree
1069therefore support certain common methods, such as \method{toxml()}
1070which returns a string containing the XML representation of the node
1071and its children. Each class also has special methods of its own; for
1072example, \class{Element} and \class{Document} instances have a method
1073to find all child elements with a given tag name. Continuing from the
1074previous 2-line example:
1075
1076\begin{verbatim}
1077perslist = doc.getElementsByTagName( 'PERSONA' )
1078print perslist[0].toxml()
1079print perslist[1].toxml()
1080\end{verbatim}
1081
1082For the \textit{Hamlet} XML file, the above few lines output:
1083
1084\begin{verbatim}
1085<PERSONA>CLAUDIUS, king of Denmark. </PERSONA>
1086<PERSONA>HAMLET, son to the late, and nephew to the present king.</PERSONA>
1087\end{verbatim}
1088
1089The root element of the document is available as
1090\code{doc.documentElement}, and its children can be easily modified
1091by deleting, adding, or removing nodes:
1092
1093\begin{verbatim}
1094root = doc.documentElement
1095
1096# Remove the first child
1097root.removeChild( root.childNodes[0] )
1098
1099# Move the new first child to the end
1100root.appendChild( root.childNodes[0] )
1101
1102# Insert the new first child (originally,
1103# the third child) before the 20th child.
1104root.insertBefore( root.childNodes[0], root.childNodes[20] )
1105\end{verbatim}
1106
1107Again, I will refer you to the Python documentation for a complete
1108listing of the different \class{Node} classes and their various methods.
1109
1110\subsection{Relationship to PyXML}
1111
1112The XML Special Interest Group has been working on XML-related Python
1113code for a while. Its code distribution, called PyXML, is available
1114from the SIG's Web pages at \url{http://www.python.org/sigs/xml-sig/}.
1115The PyXML distribution also used the package name \samp{xml}. If
1116you've written programs that used PyXML, you're probably wondering
1117about its compatibility with the 2.0 \module{xml} package.
1118
1119The answer is that Python 2.0's \module{xml} package isn't compatible
1120with PyXML, but can be made compatible by installing a recent version
1121PyXML. Many applications can get by with the XML support that is
1122included with Python 2.0, but more complicated applications will
1123require that the full PyXML package will be installed. When
1124installed, PyXML versions 0.6.0 or greater will replace the
1125\module{xml} package shipped with Python, and will be a strict
1126superset of the standard package, adding a bunch of additional
1127features. Some of the additional features in PyXML include:
1128
1129\begin{itemize}
1130\item 4DOM, a full DOM implementation
Andrew M. Kuchlingf1551702000-10-16 14:19:21 +00001131from FourThought, Inc.
Andrew M. Kuchling6032c482000-10-12 02:37:14 +00001132\item The xmlproc validating parser, written by Lars Marius Garshol.
1133\item The \module{sgmlop} parser accelerator module, written by Fredrik Lundh.
1134\end{itemize}
Andrew M. Kuchling43737642000-08-30 00:51:02 +00001135
1136% ======================================================================
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00001137\section{Module changes}
1138
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +00001139Lots of improvements and bugfixes were made to Python's extensive
1140standard library; some of the affected modules include
1141\module{readline}, \module{ConfigParser}, \module{cgi},
1142\module{calendar}, \module{posix}, \module{readline}, \module{xmllib},
1143\module{aifc}, \module{chunk, wave}, \module{random}, \module{shelve},
1144and \module{nntplib}. Consult the CVS logs for the exact
1145patch-by-patch details.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00001146
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +00001147Brian Gallew contributed OpenSSL support for the \module{socket}
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001148module. OpenSSL is an implementation of the Secure Socket Layer,
1149which encrypts the data being sent over a socket. When compiling
1150Python, you can edit \file{Modules/Setup} to include SSL support,
1151which adds an additional function to the \module{socket} module:
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +00001152\function{socket.ssl(\var{socket}, \var{keyfile}, \var{certfile})},
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001153which takes a socket object and returns an SSL socket. The
1154\module{httplib} and \module{urllib} modules were also changed to
1155support ``https://'' URLs, though no one has implemented FTP or SMTP
1156over SSL.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00001157
Andrew M. Kuchling69db0e42000-06-28 02:16:00 +00001158The \module{httplib} module has been rewritten by Greg Stein to
1159support HTTP/1.1. Backward compatibility with the 1.5 version of
1160\module{httplib} is provided, though using HTTP/1.1 features such as
1161pipelining will require rewriting code to use a different set of
1162interfaces.
1163
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +00001164The \module{Tkinter} module now supports Tcl/Tk version 8.1, 8.2, or
11658.3, and support for the older 7.x versions has been dropped. The
Andrew M. Kuchling791b3662000-07-01 15:04:18 +00001166Tkinter module now supports displaying Unicode strings in Tk widgets.
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +00001167Also, Fredrik Lundh contributed an optimization which makes operations
1168like \code{create_line} and \code{create_polygon} much faster,
Andrew M. Kuchling791b3662000-07-01 15:04:18 +00001169especially when using lots of coordinates.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00001170
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +00001171The \module{curses} module has been greatly extended, starting from
1172Oliver Andrich's enhanced version, to provide many additional
1173functions from ncurses and SYSV curses, such as colour, alternative
Andrew M. Kuchling69db0e42000-06-28 02:16:00 +00001174character set support, pads, and mouse support. This means the module
1175is no longer compatible with operating systems that only have BSD
1176curses, but there don't seem to be any currently maintained OSes that
1177fall into this category.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00001178
Andrew M. Kuchling730067e2000-06-30 01:44:05 +00001179As mentioned in the earlier discussion of 2.0's Unicode support, the
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001180underlying implementation of the regular expressions provided by the
1181\module{re} module has been changed. SRE, a new regular expression
1182engine written by Fredrik Lundh and partially funded by Hewlett
1183Packard, supports matching against both 8-bit strings and Unicode
1184strings.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00001185
1186% ======================================================================
1187\section{New modules}
1188
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001189A number of new modules were added. We'll simply list them with brief
Andrew M. Kuchling730067e2000-06-30 01:44:05 +00001190descriptions; consult the 2.0 documentation for the details of a
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001191particular module.
1192
1193\begin{itemize}
1194
Andrew M. Kuchling62cdd962000-06-30 12:46:41 +00001195\item{\module{atexit}}:
1196For registering functions to be called before the Python interpreter exits.
1197Code that currently sets
1198\code{sys.exitfunc} directly should be changed to
1199use the \module{atexit} module instead, importing \module{atexit}
1200and calling \function{atexit.register()} with
1201the function to be called on exit.
1202(Contributed by Skip Montanaro.)
1203
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001204\item{\module{codecs}, \module{encodings}, \module{unicodedata}:} Added as part of the new Unicode support.
1205
Andrew M. Kuchlingfed4f1e2000-07-01 12:33:43 +00001206\item{\module{filecmp}:} Supersedes the old \module{cmp}, \module{cmpcache} and
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001207\module{dircmp} modules, which have now become deprecated.
Andrew M. Kuchlingc0328f02000-06-10 15:11:20 +00001208(Contributed by Gordon MacMillan and Moshe Zadka.)
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001209
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +00001210\item{\module{gettext}:} This module provides internationalization
1211(I18N) and localization (L10N) support for Python programs by
1212providing an interface to the GNU gettext message catalog library.
1213(Integrated by Barry Warsaw, from separate contributions by Martin von
1214Loewis, Peter Funk, and James Henstridge.)
1215
Andrew M. Kuchling35e8afb2000-07-08 12:06:31 +00001216\item{\module{linuxaudiodev}:} Support for the \file{/dev/audio}
1217device on Linux, a twin to the existing \module{sunaudiodev} module.
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +00001218(Contributed by Peter Bosch, with fixes by Jeremy Hylton.)
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001219
1220\item{\module{mmap}:} An interface to memory-mapped files on both
1221Windows and Unix. A file's contents can be mapped directly into
1222memory, at which point it behaves like a mutable string, so its
1223contents can be read and modified. They can even be passed to
1224functions that expect ordinary strings, such as the \module{re}
1225module. (Contributed by Sam Rushing, with some extensions by
1226A.M. Kuchling.)
1227
Andrew M. Kuchling35e8afb2000-07-08 12:06:31 +00001228\item{\module{pyexpat}:} An interface to the Expat XML parser.
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001229(Contributed by Paul Prescod.)
1230
1231\item{\module{robotparser}:} Parse a \file{robots.txt} file, which is
1232used for writing Web spiders that politely avoid certain areas of a
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +00001233Web site. The parser accepts the contents of a \file{robots.txt} file,
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001234builds a set of rules from it, and can then answer questions about
1235the fetchability of a given URL. (Contributed by Skip Montanaro.)
1236
1237\item{\module{tabnanny}:} A module/script to
Andrew M. Kuchling5e08a012000-09-04 17:59:27 +00001238check Python source code for ambiguous indentation.
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001239(Contributed by Tim Peters.)
1240
Andrew M. Kuchlinga5bbb002000-06-10 02:41:46 +00001241\item{\module{UserString}:} A base class useful for deriving objects that behave like strings.
1242
Andrew M. Kuchling08d87c62000-07-09 15:05:15 +00001243\item{\module{webbrowser}:} A module that provides a platform independent
1244way to launch a web browser on a specific URL. For each platform, various
1245browsers are tried in a specific order. The user can alter which browser
1246is launched by setting the \var{BROWSER} environment variable.
1247(Originally inspired by Eric S. Raymond's patch to \module{urllib}
1248which added similar functionality, but
1249the final module comes from code originally
1250implemented by Fred Drake as \file{Tools/idle/BrowserControl.py},
1251and adapted for the standard library by Fred.)
1252
Andrew M. Kuchlingd500e442000-09-06 12:30:25 +00001253\item{\module{_winreg}:} An interface to the
Andrew M. Kuchlingfed4f1e2000-07-01 12:33:43 +00001254Windows registry. \module{_winreg} is an adaptation of functions that
1255have been part of PythonWin since 1995, but has now been added to the core
Andrew M. Kuchlingd500e442000-09-06 12:30:25 +00001256distribution, and enhanced to support Unicode.
1257\module{_winreg} was written by Bill Tutt and Mark Hammond.
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001258
1259\item{\module{zipfile}:} A module for reading and writing ZIP-format
1260archives. These are archives produced by \program{PKZIP} on
1261DOS/Windows or \program{zip} on Unix, not to be confused with
1262\program{gzip}-format files (which are supported by the \module{gzip}
1263module)
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001264(Contributed by James C. Ahlstrom.)
1265
Andrew M. Kuchling69db0e42000-06-28 02:16:00 +00001266\item{\module{imputil}:} A module that provides a simpler way for
1267writing customised import hooks, in comparison to the existing
1268\module{ihooks} module. (Implemented by Greg Stein, with much
1269discussion on python-dev along the way.)
1270
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001271\end{itemize}
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00001272
1273% ======================================================================
1274\section{IDLE Improvements}
1275
Andrew M. Kuchlingc0328f02000-06-10 15:11:20 +00001276IDLE is the official Python cross-platform IDE, written using Tkinter.
Andrew M. Kuchling730067e2000-06-30 01:44:05 +00001277Python 2.0 includes IDLE 0.6, which adds a number of new features and
Andrew M. Kuchlingc0328f02000-06-10 15:11:20 +00001278improvements. A partial list:
1279
1280\begin{itemize}
1281\item UI improvements and optimizations,
1282especially in the area of syntax highlighting and auto-indentation.
1283
1284\item The class browser now shows more information, such as the top
Andrew M. Kuchling730067e2000-06-30 01:44:05 +00001285level functions in a module.
Andrew M. Kuchlingc0328f02000-06-10 15:11:20 +00001286
1287\item Tab width is now a user settable option. When opening an existing Python
1288file, IDLE automatically detects the indentation conventions, and adapts.
1289
1290\item There is now support for calling browsers on various platforms,
1291used to open the Python documentation in a browser.
1292
1293\item IDLE now has a command line, which is largely similar to
1294the vanilla Python interpreter.
1295
1296\item Call tips were added in many places.
1297
1298\item IDLE can now be installed as a package.
1299
1300\item In the editor window, there is now a line/column bar at the bottom.
1301
1302\item Three new keystroke commands: Check module (Alt-F5), Import
Andrew M. Kuchling730067e2000-06-30 01:44:05 +00001303module (F5) and Run script (Ctrl-F5).
Andrew M. Kuchlingc0328f02000-06-10 15:11:20 +00001304
1305\end{itemize}
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00001306
1307% ======================================================================
1308\section{Deleted and Deprecated Modules}
1309
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001310A few modules have been dropped because they're obsolete, or because
1311there are now better ways to do the same thing. The \module{stdwin}
1312module is gone; it was for a platform-independent windowing toolkit
1313that's no longer developed.
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001314
Andrew M. Kuchlinga5bbb002000-06-10 02:41:46 +00001315A number of modules have been moved to the
1316\file{lib-old} subdirectory:
1317\module{cmp}, \module{cmpcache}, \module{dircmp}, \module{dump},
1318\module{find}, \module{grep}, \module{packmail},
1319\module{poly}, \module{util}, \module{whatsound}, \module{zmod}.
1320If you have code which relies on a module that's been moved to
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001321\file{lib-old}, you can simply add that directory to \code{sys.path}
Andrew M. Kuchlinga5bbb002000-06-10 02:41:46 +00001322to get them back, but you're encouraged to update any code that uses
1323these modules.
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001324
Andrew M. Kuchling730067e2000-06-30 01:44:05 +00001325\section{Acknowledgements}
Andrew M. Kuchling6c3cd8d2000-06-10 02:24:31 +00001326
Andrew M. Kuchlinga6161ed2000-07-01 00:23:02 +00001327The authors would like to thank the following people for offering
Andrew M. Kuchlinga8d10782000-10-19 01:42:33 +00001328suggestions on various drafts of this article: David Bolen, Mark Hammond, Gregg Hauser,
Andrew M. Kuchlingec1722e2000-10-12 03:04:22 +00001329Jeremy Hylton, Fredrik Lundh, Detlef Lannert, Aahz Maruch, Skip
1330Montanaro, Vladimir Marangozov, Guido van Rossum, Neil Schemenauer,
1331and Russ Schmidt.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00001332
1333\end{document}