blob: 1cdde64206297e2d0cfb59ae13cebabaf0343e93 [file] [log] [blame]
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00001\documentclass{howto}
2
3\title{What's New in Python 1.6}
4\release{0.01}
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +00005\author{A.M. Kuchling and Moshe Zadka}
6\authoraddress{\email{amk1@bigfoot.com}, \email{moshez@math.huji.ac.il} }
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +00007\begin{document}
8\maketitle\tableofcontents
9
10\section{Introduction}
11
12A new release of Python, version 1.6, will be released some time this
13summer. Alpha versions are already available from
14\url{http://www.python.org/1.6/}. This article talks about the
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000015exciting new features in 1.6, highlights some other useful changes,
16and points out a few incompatible changes that may require rewriting
17code.
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
22better error messages went into 1.6; to list them all would be
23impossible, but they're certainly significant. Consult the
24publicly-available CVS logs if you want to see the full list.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +000025
26% ======================================================================
27\section{Unicode}
28
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000029The largest new feature in Python 1.6 is a new fundamental data type:
30Unicode strings. Unicode uses 16-bit numbers to represent characters
31instead of the 8-bit number used by ASCII, meaning that 65,536
32distinct characters can be supported.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +000033
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000034The final interface for Unicode support was arrived at through
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +000035countless often-stormy discussions on the python-dev mailing list, and
36mostly implemented by Marc-Andr\'e Lemburg. A detailed explanation of
37the interface is in the file
38\file{Misc/unicode.txt} in the Python source distribution; it's also
39available on the Web at
40\url{http://starship.python.net/crew/lemburg/unicode-proposal.txt}.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000041This article will simply cover the most significant points from the
42full interface.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +000043
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000044In Python source code, Unicode strings are written as
45\code{u"string"}. Arbitrary Unicode characters can be written using a
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +000046new escape sequence, \code{\e u\var{HHHH}}, where \var{HHHH} is a
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000474-digit hexadecimal number from 0000 to FFFF. The existing
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +000048\code{\e x\var{HHHH}} escape sequence can also be used, and octal
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000049escapes can be used for characters up to U+01FF, which is represented
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +000050by \code{\e 777}.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +000051
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000052Unicode strings, just like regular strings, are an immutable sequence
53type, so they can be indexed and sliced. They also have an
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +000054\method{encode( \optional{\var{encoding}} )} method that returns an 8-bit
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000055string in the desired encoding. Encodings are named by strings, such
56as \code{'ascii'}, \code{'utf-8'}, \code{'iso-8859-1'}, or whatever.
57A codec API is defined for implementing and registering new encodings
58that are then available throughout a Python program. If an encoding
59isn't specified, the default encoding is always 7-bit ASCII. (XXX is
60that the current default encoding?)
61
62Combining 8-bit and Unicode strings always coerces to Unicode, using
63the default ASCII encoding; the result of \code{'a' + u'bc'} is
64\code{'abc'}.
65
66New built-in functions have been added, and existing built-ins
67modified to support Unicode:
68
69\begin{itemize}
70\item \code{unichr(\var{ch})} returns a Unicode string 1 character
71long, containing the character \var{ch}.
72
73\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.
74
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +000075\item \code{unicode(\var{string}, \optional{\var{encoding},}
76\optional{\var{errors}} ) } creates a Unicode string from an 8-bit
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000077string. \code{encoding} is a string naming the encoding to use.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000078The \code{errors} parameter specifies the treatment of characters that
79are invalid for the current encoding; passing \code{'strict'} as the
80value causes an exception to be raised on any encoding error, while
81\code{'ignore'} causes errors to be silently ignored and
82\code{'replace'} uses U+FFFD, the official replacement character, in
83case of any problems.
84
85\end{itemize}
86
87A new module, \module{unicodedata}, provides an interface to Unicode
88character properties. For example, \code{unicodedata.category(u'A')}
89returns the 2-character string 'Lu', the 'L' denoting it's a letter,
90and 'u' meaning that it's uppercase.
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +000091\code{u.bidirectional(u'\e x0660')} returns 'AN', meaning that U+0660 is
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +000092an Arabic number.
93
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +000094The \module{codecs} module contains functions to look up existing encodings
95and register new ones. Unless you want to implement a
96new encoding, you'll most often use the
97\function{codecs.lookup(\var{encoding})} function, which returns a
984-element tuple: \code{(\var{encode_func},
99\var{decode_func}, \var{stream_reader}, \var{stream_writer})}.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000100
101\begin{itemize}
102\item \var{encode_func} is a function that takes a Unicode string, and
103returns a 2-tuple \code{(\var{string}, \var{length})}. \var{string}
104is an 8-bit string containing a portion (perhaps all) of the Unicode
105string converted into the given encoding, and \var{length} tells you how much of the Unicode string was converted.
106
107\item \var{decode_func} is the mirror of \var{encode_func},
108taking a Unicode string and
109returns a 2-tuple \code{(\var{ustring}, \var{length})} containing a Unicode string
110and \var{length} telling you how much of the string was consumed.
111
112\item \var{stream_reader} is a class that supports decoding input from
113a stream. \var{stream_reader(\var{file_obj})} returns an object that
114supports the \method{read()}, \method{readline()}, and
115\method{readlines()} methods. These methods will all translate from
116the given encoding and return Unicode strings.
117
118\item \var{stream_writer}, similarly, is a class that supports
119encoding output to a stream. \var{stream_writer(\var{file_obj})}
120returns an object that supports the \method{write()} and
121\method{writelines()} methods. These methods expect Unicode strings, translating them to the given encoding on output.
122\end{itemize}
123
124For example, the following code writes a Unicode string into a file,
125encoding it as UTF-8:
126
127\begin{verbatim}
128import codecs
129
130unistr = u'\u0660\u2000ab ...'
131
132(UTF8_encode, UTF8_decode,
133 UTF8_streamreader, UTF8_streamwriter) = codecs.lookup('UTF-8')
134
135output = UTF8_streamwriter( open( '/tmp/output', 'wb') )
136output.write( unistr )
137output.close()
138\end{verbatim}
139
140The following code would then read UTF-8 input from the file:
141
142\begin{verbatim}
143input = UTF8_streamread( open( '/tmp/output', 'rb') )
144print repr(input.read())
145input.close()
146\end{verbatim}
147
148Unicode-aware regular expressions are available through the
149\module{re} module, which has a new underlying implementation called
150SRE written by Fredrik Lundh of Secret Labs AB.
151
152% Added -U command line option. With the option enabled the Python
153% compiler interprets all "..." strings as u"..." (same with r"..." and
154% ur"..."). (XXX Is this just for experimenting?)
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000155
156% ======================================================================
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000157\section{Distutils: Making Modules Easy to Install}
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000158
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000159Before Python 1.6, installing modules was a tedious affair -- there
160was no way to figure out automatically where Python is installed, or
161what compiler options to use for extension modules. Software authors
162had to go through an ardous ritual of editing Makefiles and
163configuration files, which only really work on Unix and leave Windows
164and MacOS unsupported. Software users faced wildly differing
165installation instructions
166
167The SIG for distribution utilities, shepherded by Greg Ward, has
168created the Distutils, a system to make package installation much
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000169easier. They form the \module{distutils} package, a new part of
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000170Python's standard library. In the best case, installing a Python
171module from source will require the same steps: first you simply mean
172unpack the tarball or zip archive, and the run ``\code{python setup.py
173install}''. The platform will be automatically detected, the compiler
174will be recognized, C extension modules will be compiled, and the
175distribution installed into the proper directory. Optional
176command-line arguments provide more control over the installation
177process, the distutils package offers many places to override defaults
178-- separating the build from the install, building or installing in
179non-default directories, and more.
180
181In order to use the Distutils, you need to write a \file{setup.py}
182script. For the simple case, when the software contains only .py
183files, a minimal \file{setup.py} can be just a few lines long:
184
185\begin{verbatim}
186from distutils.core import setup
187setup (name = "foo", version = "1.0",
188 py_modules = ["module1", "module2"])
189\end{verbatim}
190
191The \file{setup.py} file isn't much more complicated if the software
192consists of a few packages:
193
194\begin{verbatim}
195from distutils.core import setup
196setup (name = "foo", version = "1.0",
197 packages = ["package", "package.subpackage"])
198\end{verbatim}
199
200A C extension can be the most complicated case; here's an example taken from
201the PyXML package:
202
203
204\begin{verbatim}
205from distutils.core import setup, Extension
206
207expat_extension = Extension('xml.parsers.pyexpat',
208 define_macros = [('XML_NS', None)],
209 include_dirs = [ 'extensions/expat/xmltok',
210 'extensions/expat/xmlparse' ],
211 sources = [ 'extensions/pyexpat.c',
212 'extensions/expat/xmltok/xmltok.c',
213 'extensions/expat/xmltok/xmlrole.c',
214 ]
215 )
216setup (name = "PyXML", version = "0.5.4",
217 ext_modules =[ expat_extension ] )
218
219\end{verbatim}
220
221The Distutils can also take care of creating source and binary
222distributions. The ``sdist'' command, run by ``\code{python setup.py
223sdist}', builds a source distribution such as \file{foo-1.0.tar.gz}.
224Adding new commands isn't difficult, and a ``bdist_rpm'' command has
225already been contributed to create an RPM distribution for the
226software. Commands to create Windows installer programs, Debian
227packages, and Solaris .pkg files have been discussed and are in
228various stages of development.
229
230All this is documented in a new manual, \textit{Distributing Python
231Modules}.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000232
233% ======================================================================
234\section{String Methods}
235
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000236Until now string-manipulation functionality was in the \module{string}
237Python module, which was usually a front-end for the \module{strop}
238module written in C. The addition of Unicode posed a difficulty for
239the \module{strop} module, because the functions would all need to be
240rewritten in order to accept either 8-bit or Unicode strings. For
241functions such as \function{string.replace()}, which takes 3 string
242arguments, that means eight possible permutations, and correspondingly
243complicated code.
244
245Instead, Python 1.6 pushes the problem onto the string type, making
246string manipulation functionality available through methods on both
2478-bit strings and Unicode strings.
248
249\begin{verbatim}
250>>> 'andrew'.capitalize()
251'Andrew'
252>>> 'hostname'.replace('os', 'linux')
253'hlinuxtname'
254>>> 'moshe'.find('sh')
2552
256\end{verbatim}
257
258One thing that hasn't changed, April Fools' jokes notwithstanding, is
259that Python strings are immutable. Thus, the string methods return new
260strings, and do not modify the string on which they operate.
261
262The old \module{string} module is still around for backwards
263compatibility, but it mostly acts as a front-end to the new string
264methods.
265
266Two methods which have no parallel in pre-1.6 versions, although they
267did exist in JPython for quite some time, are \method{startswith()}
268and \method{endswith}. \code{s.startswith(t)} is equivalent to \code{s[:len(t)]
269== t}, while \code{s.endswith(t)} is equivalent to \code{s[-len(t):] == t}.
270
271(XXX what'll happen to join?) One other method which deserves special
272mention is \method{join}. The \method{join} method of a list receives
273one parameter, a sequence of strings, and is equivalent to the
274\function{string.join} function from the old \module{string} module,
275with the arguments reversed. In other words, \code{s.join(seq)} is
276equivalent to the old \code{string.join(seq, s)}.
277
278Some list methods, such as \method{find}, \method{index},
279\method{count}, \method{rindex}, and \method{rfind} are now available
280on strings, allowing some nice polymorphic code which can deal with
281either lists or strings without changes.
282
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000283% ======================================================================
284\section{Porting to 1.6}
285
286New Python releases try hard to be compatible with previous releases,
287and the record has been pretty good. However, some changes are
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000288considered useful enough, often fixing initial design decisions that
289turned to be actively mistaken, that breaking backward compatibility
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000290can't always be avoided. This section lists the changes in Python 1.6
291that may cause old Python code to break.
292
293The change which will probably break the most code is tightening up
294the arguments accepted by some methods. Some methods would take
295multiple arguments and treat them as a tuple, particularly various
296list methods such as \method{.append()}, \method{.insert()},
297\method{remove()}, and \method{.count()}.
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000298(XXX did anyone ever call the last 2 methods with multiple args?)
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000299In earlier versions of Python, if \code{L} is a list, \code{L.append(
3001,2 )} appends the tuple \code{(1,2)} to the list. In Python 1.6 this
301causes a \exception{TypeError} exception to be raised, with the
302message: 'append requires exactly 1 argument; 2 given'. The fix is to
303simply add an extra set of parentheses to pass both values as a tuple:
304\code{L.append( (1,2) )}.
305
306The earlier versions of these methods were more forgiving because they
307used an old function in Python's C interface to parse their arguments;
3081.6 modernizes them to use \function{PyArg_ParseTuple}, the current
309argument parsing function, which provides more helpful error messages
310and treats multi-argument calls as errors. If you absolutely must use
3111.6 but can't fix your code, you can edit \file{Objects/listobject.c}
312and define the preprocessor symbol \code{NO_STRICT_LIST_APPEND} to
313preserve the old behaviour; this isn't recommended.
314
315Some of the functions in the \module{socket} module are still
316forgiving in this way. For example, \function{socket.connect(
317('hostname', 25) )} is the correct form, passing a tuple representing
318an IP address, but
319\function{socket.connect( 'hostname', 25 )} also
320works. \function{socket.connect_ex()} and \function{socket.bind()} are
321similarly easy-going. 1.6alpha1 tightened these functions up, but
322because the documentation actually used the erroneous multiple
323argument form, many people wrote code which will break. So for
324the\module{socket} module, the documentation was fixed and the
325multiple argument form is simply marked as deprecated; it'll be
326removed in a future Python version.
327
328Some work has been done to make integers and long integers a bit more
329interchangeable. In 1.5.2, large-file support was added for Solaris,
330to allow reading files larger than 2Gb; this made the \method{tell()}
331method of file objects return a long integer instead of a regular
332integer. Some code would subtract two file offsets and attempt to use
333the result to multiply a sequence or slice a string, but this raised a
334\exception{TypeError}. In 1.6, long integers can be used to multiply
335or slice a sequence, and it'll behave as you'd intuitively expect it to;
336\code{3L * 'abc'} produces 'abcabcabc', and
337\code{ (0,1,2,3)[2L:4L]} produces (2,3). Long integers can also be
338used in various new places where previously only integers were
339accepted, such as in the \method{seek()} method of file objects.
340
341The subtlest long integer change of all is that the \function{str()}
342of a long integer no longer has a trailing 'L' character, though
343\function{repr()} still includes it. The 'L' annoyed many people who
344wanted to print long integers that looked just like regular integers,
345since they had to go out of their way to chop off the character. This
346is no longer a problem in 1.6, but code which assumes the 'L' is
347there, and does \code{str(longval)[:-1]} will now lose the final
348digit.
349
350Taking the \function{repr()} of a float now uses a different
351formatting precision than \function{str()}. \function{repr()} uses
352``%.17g'' format string for C's \function{sprintf()}, while
353\function{str()} uses ``%.12g'' as before. The effect is that
354\function{repr()} may occasionally show more decimal places than
355\function{str()}, for numbers
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000356XXX need example value here to demonstrate problem.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000357
358
359% ======================================================================
360\section{Core Changes}
361
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000362Various minor changes have been made to Python's syntax and built-in
363functions. None of the changes are very far-reaching, but they're
364handy conveniences.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000365
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000366A change to syntax makes it more convenient to call a given function
367with a tuple of arguments and/or a dictionary of keyword arguments.
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000368In Python 1.5 and earlier, you do this with the \function{apply()}
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000369built-in function: \code{apply(f, \var{args}, \var{kw})} calls the
370function \function{f()} with the argument tuple \var{args} and the
371keyword arguments in the dictionary \var{kw}. Thanks to a patch from
372Greg Ewing, 1.6 adds \code{f(*\var{args}, **\var{kw})} as a shorter
373and clearer way to achieve the same effect. This syntax is
374symmetrical with the syntax for defining functions:
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000375
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000376\begin{verbatim}
377def f(*args, **kw):
378 # args is a tuple of positional args,
379 # kw is a dictionary of keyword args
380 ...
381\end{verbatim}
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000382
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000383A new format style is available when using the \code{\%} operator.
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000384'\%r' will insert the \function{repr()} of its argument. This was
385also added from symmetry considerations, this time for symmetry with
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000386the existing '\%s' format style, which inserts the \function{str()} of
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000387its argument. For example, \code{'\%r \%s' \% ('abc', 'abc')} returns a
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000388string containing \verb|'abc' abc|.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000389
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000390The \function{int()} and \function{long()} functions now accept an
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000391optional ``base'' parameter when the first argument is a string.
392\code{int('123', 10)} returns 123, while \code{int('123', 16)} returns
393291. \code{int(123, 16)} raises a \exception{TypeError} exception
394with the message ``can't convert non-string with explicit base''.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000395
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000396Previously there was no way to implement a class that overrode
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000397Python's built-in \keyword{in} operator and implemented a custom
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000398version. \code{\var{obj} in \var{seq}} returns true if \var{obj} is
399present in the sequence \var{seq}; Python computes this by simply
400trying every index of the sequence until either \var{obj} is found or
401an \exception{IndexError} is encountered. Moshe Zadka contributed a
402patch which adds a \method{__contains__} magic method for providing a
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000403custom implementation for \keyword{in}. Additionally, new built-in
404objects written in C can define what \keyword{in} means for them via a
405new slot in the sequence protocol.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000406
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000407Earlier versions of Python used a recursive algorithm for deleting
408objects. Deeply nested data structures could cause the interpreter to
409fill up the C stack and crash; Christian Tismer rewrote the deletion
410logic to fix this problem. On a related note, comparing recursive
411objects recursed infinitely and crashed; Jeremy Hylton rewrote the
412code to no longer crash, producing a useful result instead. For
413example, after this code:
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000414
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000415\begin{verbatim}
416a = []
417b = []
418a.append(a)
419b.append(b)
420\end{verbatim}
421
422The comparison \code{a==b} returns true, because the two recursive
423data structures are isomorphic.
424\footnote{See the thread ``trashcan and PR\#7'' in the April 2000 archives of the python-dev mailing list for the discussion leading up to this implementation, and some useful relevant links.
425%http://www.python.org/pipermail/python-dev/2000-April/004834.html
426}
427
428Work has been done on porting Python to 64-bit Windows on the Itanium
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000429processor, mostly by Trent Mick of ActiveState. (Confusingly, \code{sys.platform} is still \code{'win32'} on
430Win64 because it seems that for ease of porting, MS Visual C++ treats code
431as 32 bit.
432) PythonWin also supports Windows CE; see the Python CE page at
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000433\url{http://www.python.net/crew/mhammond/ce/} for more information.
434
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000435An attempt has been made to alleviate one of Python's warts, the
436often-confusing \exception{NameError} exception when code refers to a
437local variable before the variable has been assigned a value. For
438example, the following code raises an exception on the \keyword{print}
439statement in both 1.5.2 and 1.6; in 1.5.2 a \exception{NameError}
440exception is raised, while 1.6 raises \exception{UnboundLocalError}.
441
442\begin{verbatim}
443def f():
444 print "i=",i
445 i = i + 1
446f()
447\end{verbatim}
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000448
449A new variable holding more detailed version information has been
450added to the \module{sys} module. \code{sys.version_info} is a tuple
451\code{(\var{major}, \var{minor}, \var{micro}, \var{level},
452\var{serial})} For example, in 1.6a2 \code{sys.version_info} is
453\code{(1, 6, 0, 'alpha', 2)}. \var{level} is a string such as
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000454\code{"alpha"}, \code{"beta"}, or \code{""} for a final release.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000455
456% ======================================================================
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000457\section{Extending/Embedding Changes}
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000458
459Some of the changes are under the covers, and will only be apparent to
460people writing C extension modules, or embedding a Python interpreter
461in a larger application. If you aren't dealing with Python's C API,
Andrew M. Kuchling5b8311e2000-05-31 03:28:42 +0000462you can safely skip this section.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000463
464Users of Jim Fulton's ExtensionClass module will be pleased to find
465out that hooks have been added so that ExtensionClasses are now
466supported by \function{isinstance()} and \function{issubclass()}.
467This means you no longer have to remember to write code such as
468\code{if type(obj) == myExtensionClass}, but can use the more natural
469\code{if isinstance(obj, myExtensionClass)}.
470
Andrew M. Kuchlingb853ea02000-06-03 03:06:58 +0000471The \file{Python/importdl.c} file, which was a mass of \#ifdefs to
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000472support dynamic loading on many different platforms, was cleaned up
473are reorganized by Greg Stein. \file{importdl.c} is now quite small,
474and platform-specific code has been moved into a bunch of
475\file{Python/dynload_*.c} files.
476
477Vladimir Marangozov's long-awaited malloc restructuring was completed,
478to make it easy to have the Python interpreter use a custom allocator
479instead of C's standard \function{malloc()}. For documentation, read
480the comments in \file{Include/mymalloc.h} and
481\file{Include/objimpl.h}. For the lengthy discussions during which
482the interface was hammered out, see the Web archives of the 'patches'
483and 'python-dev' lists at python.org.
484
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000485Recent versions of the GUSI (XXX what is GUSI?)
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000486development environment for MacOS support POSIX threads. Therefore,
487POSIX threads are now supported on the Macintosh too. Threading
488support using the user-space GNU pth library was also contributed.
489
490Threading support on Windows was enhanced, too. Windows supports
491thread locks that use kernel objects only in case of contention; in
492the common case when there's no contention, they use simpler functions
493which are an order of magnitude faster. A threaded version of Python
4941.5.2 on NT is twice as slow as an unthreaded version; with the 1.6
495changes, the difference is only 10\%. These improvements were
496contributed by Yakov Markovitch.
497
498% ======================================================================
499\section{Module changes}
500
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000501Lots of improvements and bugfixes were made to Python's extensive
502standard library; some of the affected modules include
503\module{readline}, \module{ConfigParser}, \module{cgi},
504\module{calendar}, \module{posix}, \module{readline}, \module{xmllib},
505\module{aifc}, \module{chunk, wave}, \module{random}, \module{shelve},
506and \module{nntplib}. Consult the CVS logs for the exact
507patch-by-patch details.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000508
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000509Brian Gallew contributed OpenSSL support for the \module{socket}
510module. When compiling Python, you can edit \file{Modules/Setup} to
511include SSL support. When enabled, an additional function
512\function{socket.ssl(\var{socket}, \var{keyfile}, \var{certfile})},
513which takes a socket object and returns an SSL socket. When SSL
514support is available, the \module{httplib} and \module{urllib} modules
515will support ``https://'' URLs.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000516
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000517The \module{Tkinter} module now supports Tcl/Tk version 8.1, 8.2, or
5188.3, and support for the older 7.x versions has been dropped. The
519Tkinter module also supports displaying Unicode strings in Tk
520widgets.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000521
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000522The \module{curses} module has been greatly extended, starting from
523Oliver Andrich's enhanced version, to provide many additional
524functions from ncurses and SYSV curses, such as colour, alternative
525character set support, pads, and other new features. This means the
526module is no longer compatible with operating systems that only have
527BSD curses, but there don't seem to be any currently maintained OSes
528that fall into this category.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000529
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000530XXX re - changed to be a frontend to sre
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000531
532% ======================================================================
533\section{New modules}
534
535winreg - Windows registry interface.
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000536PyExpat - interface to Expat XML parser
537robotparser - parse a robots.txt file (for writing web spiders)
538linuxaudio - audio for Linux
539mmap - treat a file as a memory buffer
540filecmp - supersedes the old cmp.py and dircmp.py modules
541tabnanny - check Python sources for tab-width dependance
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000542
543% ======================================================================
544\section{IDLE Improvements}
545
546XXX IDLE -- complete overhaul; what are the changes?
547
548% ======================================================================
549\section{Deleted and Deprecated Modules}
550
Andrew M. Kuchlingfa33a4e2000-06-03 02:52:40 +0000551XXX stdwin, others?
Andrew M. Kuchling25bfd0e2000-05-27 11:28:26 +0000552
553\end{document}
554