blob: e3ea276bb7ae1d0961aabddb1a1257e6d8c27b96 [file] [log] [blame]
Tim Petersd7b5e882001-01-25 03:36:26 +00001What's New in Python 2.1 alpha 2?
2=================================
Tim Peters40ead762001-01-27 05:35:26 +00003
Tim Petersd7b5e882001-01-25 03:36:26 +00004Core language, builtins, and interpreter
5
Tim Peters40ead762001-01-27 05:35:26 +00006- repr(string) is easier to read, now using hex escapes instead of octal,
7 and using \t, \n and \r instead of \011, \012 and \015 (respectively):
8
9 >>> "\texample \r\n" + chr(0) + chr(255)
10 '\texample \r\n\x00\xff' # in 2.1
11 '\011example \015\012\000\377' # in 2.0
12
Moshe Zadka6af0ce02001-01-29 06:41:00 +000013- Functions are now compared and hashed by identity, not by value, since
14 the func_code attribute is writable.
15
Tim Petersd7b5e882001-01-25 03:36:26 +000016
17Standard library
18
19- random.py is now self-contained, and offers all the functionality of
20 the now-deprecated whrandom.py. See the docs for details. random.py
21 also supports new functions getstate() and setstate(), for saving
Tim Petersd52269b2001-01-25 06:23:18 +000022 and restoring the internal state of the generator; and jumpahead(n),
23 for quickly forcing the internal state to be the same as if n calls to
24 random() had been made. The latter is particularly useful for multi-
25 threaded programs, creating one instance of the random.Random() class for
26 each thread, then using .jumpahead() to force each instance to use a
27 non-overlapping segment of the full period.
Tim Petersd7b5e882001-01-25 03:36:26 +000028
29
Tim Petersa3a3a032000-11-30 05:22:44 +000030What's New in Python 2.1 alpha 1?
31=================================
32
33Core language, builtins, and interpreter
34
Marc-André Lemburgebb195b2001-01-20 10:34:52 +000035- There is a new Unicode companion to the PyObject_Str() API
36 called PyObject_Unicode(). It behaves in the same way as the
37 former, but assures that the returned value is an Unicode object
38 (applying the usual coercion if necessary).
Marc-André Lemburgad7c98e2001-01-17 17:09:53 +000039
Guido van Rossumf98eda02001-01-17 15:54:45 +000040- The comparison operators support "rich comparison overloading" (PEP
41 207). C extension types can provide a rich comparison function in
42 the new tp_richcompare slot in the type object. The cmp() function
43 and the C function PyObject_Compare() first try the new rich
44 comparison operators before trying the old 3-way comparison. There
45 is also a new C API PyObject_RichCompare() (which also falls back on
46 the old 3-way comparison, but does not constrain the outcome of the
47 rich comparison to a Boolean result).
48
49 The rich comparison function takes two objects (at least one of
50 which is guaranteed to have the type that provided the function) and
51 an integer indicating the opcode, which can be Py_LT, Py_LE, Py_EQ,
52 Py_NE, Py_GT, Py_GE (for <, <=, ==, !=, >, >=), and returns a Python
53 object, which may be NotImplemented (in which case the tp_compare
54 slot function is used as a fallback, if defined).
55
56 Classes can overload individual comparison operators by defining one
57 or more of the methods__lt__, __le__, __eq__, __ne__, __gt__,
Guido van Rossuma88479f2001-01-18 14:28:08 +000058 __ge__. There are no explicit "reflected argument" versions of
59 these; instead, __lt__ and __gt__ are each other's reflection,
60 likewise for__le__ and __ge__; __eq__ and __ne__ are their own
61 reflection (similar at the C level). No other implications are
62 made; in particular, Python does not assume that == is the Boolean
63 inverse of !=, or that < is the Boolean inverse of >=. This makes
64 it possible to define types with partial orderings.
Guido van Rossumf98eda02001-01-17 15:54:45 +000065
66 Classes or types that want to implement (in)equality tests but not
67 the ordering operators (i.e. unordered types) should implement ==
68 and !=, and raise an error for the ordering operators.
69
Guido van Rossuma88479f2001-01-18 14:28:08 +000070 It is possible to define types whose rich comparison results are not
Guido van Rossumf98eda02001-01-17 15:54:45 +000071 Boolean; e.g. a matrix type might want to return a matrix of bits
72 for A < B, giving elementwise comparisons. Such types should ensure
73 that any interpretation of their value in a Boolean context raises
74 an exception, e.g. by defining __nonzero__ (or the tp_nonzero slot
75 at the C level) to always raise an exception.
76
Guido van Rossuma88479f2001-01-18 14:28:08 +000077- Complex numbers use rich comparisons to define == and != but raise
78 an exception for <, <=, > and >=. Unfortunately, this also means
79 that cmp() of two complex numbers raises an exception when the two
80 numbers differ. Since it is not mathematically meaningful to compare
81 complex numbers except for equality, I hope that this doesn't break
82 too much code.
83
Barry Warsaw573b5412001-01-15 20:43:18 +000084- Functions and methods now support getting and setting arbitrarily
85 named attributes (PEP 232). Functions have a new __dict__
86 (a.k.a. func_dict) which hold the function attributes. Methods get
87 and set attributes on their underlying im_func. It is a TypeError
88 to set an attribute on a bound method.
89
Guido van Rossum051e3352001-01-15 19:11:10 +000090- The xrange() object implementation has been improved so that
91 xrange(sys.maxint) can be used on 64-bit platforms. There's still a
92 limitation that in this case len(xrange(sys.maxint)) can't be
93 calculated, but the common idiom "for i in xrange(sys.maxint)" will
94 work fine as long as the index i doesn't actually reach 2**31.
95 (Python uses regular ints for sequence and string indices; fixing
96 that is much more work.)
97
Guido van Rossum1cc8f832001-01-12 16:25:08 +000098- Two changes to from...import:
99
100 1) "from M import X" now works even if M is not a real module; it's
101 basically a getattr() operation with AttributeError exceptions
102 changed into ImportError.
103
104 2) "from M import *" now looks for M.__all__ to decide which names to
105 import; if M.__all__ doesn't exist, it uses M.__dict__.keys() but
106 filters out names starting with '_' as before. Whether or not
107 __all__ exists, there's no restriction on the type of M.
108
Guido van Rossumf61f1662001-01-10 20:13:55 +0000109- File objects have a new method, xreadlines(). This is the fastest
110 way to iterate over all lines in a file:
111
112 for line in file.xreadlines():
113 ...do something to line...
114
115 See the xreadlines module (mentioned below) for how to do this for
116 other file-like objects.
117
118- Even if you don't use file.xreadlines(), you may expect a speedup on
119 line-by-line input. The file.readline() method has been optimized
Tim Petersf29b64d2001-01-15 06:33:19 +0000120 quite a bit in platform-specific ways: on systems (like Linux) that
121 support flockfile(), getc_unlocked(), and funlockfile(), those are
122 used by default. On systems (like Windows) without getc_unlocked(),
123 a complicated (but still thread-safe) method using fgets() is used by
124 default.
125
Tim Petersd52269b2001-01-25 06:23:18 +0000126 You can force use of the fgets() method by #define'ing
127 USE_FGETS_IN_GETLINE at build time (it may be faster than
Tim Petersf29b64d2001-01-15 06:33:19 +0000128 getc_unlocked()).
129
Tim Petersd52269b2001-01-25 06:23:18 +0000130 You can force fgets() not to be used by #define'ing
131 DONT_USE_FGETS_IN_GETLINE (this is the first thing to try if std test
Tim Petersf29b64d2001-01-15 06:33:19 +0000132 test_bufio.py fails -- and let us know if it does!).
133
134- In addition, the fileinput module, while still slower than the other
135 methods on most platforms, has been sped up too, by using
136 file.readlines(sizehint).
Guido van Rossumf61f1662001-01-10 20:13:55 +0000137
138- Support for run-time warnings has been added, including a new
139 command line option (-W) to specify the disposition of warnings.
140 See the description of the warnings module below.
141
142- Extensive changes have been made to the coercion code. This mostly
143 affects extension modules (which can now implement mixed-type
144 numerical operators without having to use coercion), but
145 occasionally, in boundary cases the coercion semantics have changed
146 subtly. Since this was a terrible gray area of the language, this
Guido van Rossumae72d872001-01-11 15:00:14 +0000147 is considered an improvement. Also note that __rcmp__ is no longer
Guido van Rossumf61f1662001-01-10 20:13:55 +0000148 supported -- instead of calling __rcmp__, __cmp__ is called with
Guido van Rossuma88479f2001-01-18 14:28:08 +0000149 reflected arguments.
Guido van Rossumf61f1662001-01-10 20:13:55 +0000150
Guido van Rossumf98eda02001-01-17 15:54:45 +0000151- In connection with the coercion changes, a new built-in singleton
152 object, NotImplemented is defined. This can be returned for
153 operations that wish to indicate they are not implemented for a
154 particular combination of arguments. From C, this is
155 Py_NotImplemented.
156
Martin v. Löwisbe4c0f52001-01-04 20:30:56 +0000157- The interpreter accepts now bytecode files on the command line even
158 if they do not have a .pyc or .pyo extension. On Linux, after executing
159
160 echo ':pyc:M::\x87\xc6\x0d\x0a::/usr/local/bin/python:' > /proc/sys/fs/binfmt_misc/register
161
162 any byte code file can be used as an executable (i.e. as an argument
163 to execve(2)).
164
Tim Peters9940b802000-12-01 07:59:35 +0000165- %[xXo] formats of negative Python longs now produce a sign
Tim Petersa3a3a032000-11-30 05:22:44 +0000166 character. In 1.6 and earlier, they never produced a sign,
167 and raised an error if the value of the long was too large
168 to fit in a Python int. In 2.0, they produced a sign if and
169 only if too large to fit in an int. This was inconsistent
170 across platforms (because the size of an int varies across
171 platforms), and inconsistent with hex() and oct(). Example:
172
173 >>> "%x" % -0x42L
Tim Peters9940b802000-12-01 07:59:35 +0000174 '-42' # in 2.1
Tim Petersa3a3a032000-11-30 05:22:44 +0000175 'ffffffbe' # in 2.0 and before, on 32-bit machines
176 >>> hex(-0x42L)
177 '-0x42L' # in all versions of Python
178
Tim Peters9940b802000-12-01 07:59:35 +0000179 The behavior of %d formats for negative Python longs remains
180 the same as in 2.0 (although in 1.6 and before, they raised
181 an error if the long didn't fit in a Python int).
182
183 %u formats don't make sense for Python longs, but are allowed
184 and treated the same as %d in 2.1. In 2.0, a negative long
185 formatted via %u produced a sign if and only if too large to
186 fit in an int. In 1.6 and earlier, a negative long formatted
187 via %u raised an error if it was too big to fit in an int.
188
Guido van Rossum3661d392000-12-12 22:10:31 +0000189- Dictionary objects have an odd new method, popitem(). This removes
190 an arbitrary item from the dictionary and returns it (in the form of
191 a (key, value) pair). This can be useful for algorithms that use a
192 dictionary as a bag of "to do" items and repeatedly need to pick one
193 item. Such algorithms normally end up running in quadratic time;
194 using popitem() they can usually be made to run in linear time.
195
Tim Peters36cdad12000-12-29 02:06:45 +0000196Standard library
197
Thomas Woutersfe385252001-01-19 23:16:56 +0000198- In the time module, the time argument to the functions strftime,
199 localtime, gmtime, asctime and ctime is now optional, defaulting to
200 the current time (in the local timezone).
201
Guido van Rossumda91f222001-01-15 16:36:08 +0000202- The ftplib module now defaults to passive mode, which is deemed a
203 more useful default given that clients are often inside firewalls
204 these days. Note that this could break if ftplib is used to connect
205 to a *server* that is inside a firewall, from outside; this is
206 expected to be a very rare situation. To fix that, you can call
207 ftp.set_pasv(0).
208
Martin v. Löwis10a27872001-01-13 09:54:41 +0000209- The module site now treats .pth files not only for path configuration,
210 but also supports extensions to the initialization code: Lines starting
211 with import are executed.
212
Guido van Rossumf61f1662001-01-10 20:13:55 +0000213- There's a new module, warnings, which implements a mechanism for
214 issuing and filtering warnings. There are some new built-in
215 exceptions that serve as warning categories, and a new command line
216 option, -W, to control warnings (e.g. -Wi ignores all warnings, -We
217 turns warnings into errors). warnings.warn(message[, category])
218 issues a warning message; this can also be called from C as
219 PyErr_Warn(category, message).
220
221- A new module xreadlines was added. This exports a single factory
222 function, xreadlines(). The intention is that this code is the
223 absolutely fastest way to iterate over all lines in an open
224 file(-like) object:
225
226 import xreadlines
227 for line in xreadlines.xreadlines(file):
228 ...do something to line...
229
230 This is equivalent to the previous the speed record holder using
231 file.readlines(sizehint). Note that if file is a real file object
232 (as opposed to a file-like object), this is equivalent:
233
234 for line in file.xreadlines():
235 ...do something to line...
236
Tim Peters36cdad12000-12-29 02:06:45 +0000237- The bisect module has new functions bisect_left, insort_left,
238 bisect_right and insort_right. The old names bisect and insort
239 are now aliases for bisect_right and insort_right. XXX_right
240 and XXX_left methods differ in what happens when the new element
241 compares equal to one or more elements already in the list: the
242 XXX_left methods insert to the left, the XXX_right methods to the
Tim Peters742bb6f2001-01-05 08:05:32 +0000243 right. Code that doesn't care where equal elements end up should
244 continue to use the old, short names ("bisect" and "insort").
Tim Peters36cdad12000-12-29 02:06:45 +0000245
Andrew M. Kuchlingf6f3a892001-01-13 14:53:34 +0000246- The new curses.panel module wraps the panel library that forms part
247 of SYSV curses and ncurses. Contributed by Thomas Gellekum.
248
Guido van Rossumf61f1662001-01-10 20:13:55 +0000249- The SocketServer module now sets the allow_reuse_address flag by
250 default in the TCPServer class.
251
252- A new function, sys._getframe(), returns the stack frame pointer of
253 the caller. This is intended only as a building block for
254 higher-level mechanisms such as string interpolation.
255
256Build issues
257
Guido van Rossum1e33bdc2001-01-23 03:17:00 +0000258- For Unix (and Unix-compatible) builds, configuration and building of
259 extension modules is now greatly automated. Rather than having to
260 edit the Modules/Setup file to indicate which modules should be
261 built and where their include files and libraries are, a
262 distutils-based setup.py script now takes care of building most
263 extension modules. All extension modules built this way are built
264 as shared libraries. Only a few modules that must be linked
265 statically are still listed in the Setup file; you won't need to
266 edit their configuration.
267
268- Python should now build out of the box on Cygwin. If it doesn't,
269 mail to Jason Tishler (jlt63 at users.sourceforge.net).
Guido van Rossumf61f1662001-01-10 20:13:55 +0000270
271- Python now always uses its own (renamed) implementation of getopt()
272 -- there's too much variation among C library getopt()
273 implementations.
274
275- C++ compilers are better supported; the CXX macro is always set to a
276 C++ compiler if one is found.
Tim Peters36cdad12000-12-29 02:06:45 +0000277
Tim Petersd92dfe02000-12-12 01:18:41 +0000278Windows changes
279
280- select module: By default under Windows, a select() call
281 can specify no more than 64 sockets. Python now boosts
282 this Microsoft default to 512. If you need even more than
283 that, see the MS docs (you'll need to #define FD_SETSIZE
284 and recompile Python from source).
285
Guido van Rossumf61f1662001-01-10 20:13:55 +0000286- Support for Windows 3.1, DOS and OS/2 is gone. The Lib/dos-8x3
287 subdirectory is no more!
288
Tim Petersa3a3a032000-11-30 05:22:44 +0000289
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000290What's New in Python 2.0?
Fred Drake1a640502000-10-16 20:27:25 +0000291=========================
Guido van Rossum61000331997-08-15 04:39:58 +0000292
Guido van Rossum8ed602b2000-09-01 22:34:33 +0000293Below is a list of all relevant changes since release 1.6. Older
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000294changes are in the file HISTORY. If you are making the jump directly
295from Python 1.5.2 to 2.0, make sure to read the section for 1.6 in the
296HISTORY file! Many important changes listed there.
Guido van Rossum61000331997-08-15 04:39:58 +0000297
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000298Alternatively, a good overview of the changes between 1.5.2 and 2.0 is
299the document "What's New in Python 2.0" by Kuchling and Moshe Zadka:
300http://starship.python.net/crew/amk/python/writing/new-python/.
Guido van Rossum1f83cce1997-10-06 21:04:35 +0000301
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000302--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)
Guido van Rossum437cfe81999-04-08 20:17:57 +0000303
304======================================================================
305
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000306What's new in 2.0 (since release candidate 1)?
307==============================================
308
309Standard library
310
311- The copy_reg module was modified to clarify its intended use: to
312 register pickle support for extension types, not for classes.
313 pickle() will raise a TypeError if it is passed a class.
314
315- Fixed a bug in gettext's "normalize and expand" code that prevented
316 it from finding an existing .mo file.
317
318- Restored support for HTTP/0.9 servers in httplib.
319
Tim Peters989b7b92000-10-16 20:24:53 +0000320- The math module was changed to stop raising OverflowError in case of
321 underflow, and return 0 instead in underflow cases. Whether Python
322 used to raise OverflowError in case of underflow was platform-
323 dependent (it did when the platform math library set errno to ERANGE
324 on underflow).
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000325
326- Fixed a bug in StringIO that occurred when the file position was not
327 at the end of the file and write() was called with enough data to
328 extend past the end of the file.
329
330- Fixed a bug that caused Tkinter error messages to get lost on
331 Windows. The bug was fixed by replacing direct use of
332 interp->result with Tcl_GetStringResult(interp).
333
334- Fixed bug in urllib2 that caused it to fail when it received an HTTP
335 redirect response.
336
337- Several changes were made to distutils: Some debugging code was
338 removed from util. Fixed the installer used when an external zip
339 program (like WinZip) is not found; the source code for this
340 installer is in Misc/distutils. check_lib() was modified to behave
341 more like AC_CHECK_LIB by add other_libraries() as a parameter. The
342 test for whether installed modules are on sys.path was changed to
343 use both normcase() and normpath().
344
Jeremy Hyltond867a2c2000-10-16 20:41:38 +0000345- Several minor bugs were fixed in the xml package (the minidom,
346 pulldom, expatreader, and saxutils modules).
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000347
348- The regression test driver (regrtest.py) behavior when invoked with
349 -l changed: It now reports a count of objects that are recognized as
350 garbage but not freed by the garbage collector.
351
Tim Peters989b7b92000-10-16 20:24:53 +0000352- The regression test for the math module was changed to test
353 exceptional behavior when the test is run in verbose mode. Python
354 cannot yet guarantee consistent exception behavior across platforms,
355 so the exception part of test_math is run only in verbose mode, and
356 may fail on your platform.
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000357
358Internals
359
360- PyOS_CheckStack() has been disabled on Win64, where it caused
361 test_sre to fail.
362
363Build issues
364
365- Changed compiler flags, so that gcc is always invoked with -Wall and
366 -Wstrict-prototypes. Users compiling Python with GCC should see
367 exactly one warning, except if they have passed configure the
Tim Peters989b7b92000-10-16 20:24:53 +0000368 --with-pydebug flag. The expected warning is for getopt() in
Tim Petersadfb94f2000-10-16 20:51:33 +0000369 Modules/main.c. This warning will be fixed for Python 2.1.
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000370
Tim Petersa3a3a032000-11-30 05:22:44 +0000371- Fixed configure to add -threads argument during linking on OSF1.
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000372
373Tools and other miscellany
374
375- The compiler in Tools/compiler was updated to support the new
376 language features introduced in 2.0: extended print statement, list
377 comprehensions, and augmented assignments. The new compiler should
378 also be backwards compatible with Python 1.5.2; the compiler will
379 always generate code for the version of the interpreter it runs
Tim Petersa3a3a032000-11-30 05:22:44 +0000380 under.
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000381
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000382What's new in 2.0 release candidate 1 (since beta 2)?
383=====================================================
384
Jeremy Hylton6040aaa2000-10-09 21:27:22 +0000385What is release candidate 1?
386
387We believe that release candidate 1 will fix all known bugs that we
388intend to fix for the 2.0 final release. This release should be a bit
389more stable than the previous betas. We would like to see even more
390widespread testing before the final release, so we are producing this
391release candidate. The final release will be exactly the same unless
392any show-stopping (or brown bag) bugs are found by testers of the
393release candidate.
394
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000395All the changes since the last beta release are bug fixes or changes
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000396to support building Python for specific platforms.
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000397
398Core language, builtins, and interpreter
399
400- A bug that caused crashes when __coerce__ was used with augmented
401 assignment, e.g. +=, was fixed.
402
403- Raise ZeroDivisionError when raising zero to a negative number,
404 e.g. 0.0 ** -2.0. Note that math.pow is unrelated to the builtin
405 power operator and the result of math.pow(0.0, -2.0) will vary by
406 platform. On Linux, it raises a ValueError.
407
408- A bug in Unicode string interpolation was fixed that occasionally
409 caused errors with formats including "%%". For example, the
410 following expression "%% %s" % u"abc" no longer raises a TypeError.
411
412- Compilation of deeply nested expressions raises MemoryError instead
413 of SyntaxError, e.g. eval("[" * 50 + "]" * 50).
414
415- In 2.0b2 on Windows, the interpreter wrote .pyc files in text mode,
416 rendering them useless. They are now written in binary mode again.
417
418Standard library
419
420- Keyword arguments are now accepted for most pattern and match object
421 methods in SRE, the standard regular expression engine.
422
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000423- In SRE, fixed error with negative lookahead and lookbehind that
Jeremy Hylton32e20ff2000-10-09 19:48:11 +0000424 manifested itself as a runtime error in patterns like "(?<!abc)(def)".
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000425
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000426- Several bugs in the Unicode handling and error handling in _tkinter
427 were fixed.
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000428
429- Fix memory management errors in Merge() and Tkapp_Call() routines.
430
431- Several changes were made to cStringIO to make it compatible with
432 the file-like object interface and with StringIO. If operations are
433 performed on a closed object, an exception is raised. The truncate
434 method now accepts a position argument and readline accepts a size
Tim Petersa3a3a032000-11-30 05:22:44 +0000435 argument.
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000436
437- There were many changes made to the linuxaudiodev module and its
438 test suite; as a result, a short, unexpected audio sample should now
Tim Petersa3a3a032000-11-30 05:22:44 +0000439 play when the regression test is run.
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000440
441 Note that this module is named poorly, because it should work
442 correctly on any platform that supports the Open Sound System
Tim Petersa3a3a032000-11-30 05:22:44 +0000443 (OSS).
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000444
445 The module now raises exceptions when errors occur instead of
446 crashing. It also defines the AFMT_A_LAW format (logarithmic A-law
447 audio) and defines a getptr() method that calls the
448 SNDCTL_DSP_GETxPTR ioctl defined in the OSS Programmer's Guide.
449
450- The library_version attribute, introduced in an earlier beta, was
451 removed because it can not be supported with early versions of the C
452 readline library, which provides no way to determine the version at
453 compile-time.
454
455- The binascii module is now enabled on Win64.
456
Tim Peters46446d62000-10-09 21:19:31 +0000457- tokenize.py no longer suffers "recursion depth" errors when parsing
458 programs with very long string literals.
459
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000460Internals
461
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000462- Fixed several buffer overflow vulnerabilities in calculate_path(),
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000463 which is called when the interpreter starts up to determine where
464 the standard library is installed. These vulnerabilities affect all
465 previous versions of Python and can be exploited by setting very
466 long values for PYTHONHOME or argv[0]. The risk is greatest for a
467 setuid Python script, although use of the wrapper in
468 Misc/setuid-prog.c will eliminate the vulnerability.
469
470- Fixed garbage collection bugs in instance creation that were
471 triggered when errors occurred during initialization. The solution,
472 applied in cPickle and in PyInstance_New(), is to call
473 PyObject_GC_Init() after the initialization of the object's
474 container attributes is complete.
475
476- pyexpat adds definitions of PyModule_AddStringConstant and
477 PyModule_AddObject if the Python version is less than 2.0, which
478 provides compatibility with PyXML on Python 1.5.2.
479
480- If the platform has a bogus definition for LONG_BIT (the number of
481 bits in a long), an error will be reported at compile time.
482
483- Fix bugs in _PyTuple_Resize() which caused hard-to-interpret garbage
484 collection crashes and possibly other, unreported crashes.
485
486- Fixed a memory leak in _PyUnicode_Fini().
487
488Build issues
489
490- configure now accepts a --with-suffix option that specifies the
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000491 executable suffix. This is useful for builds on Cygwin and Mac OS
Tim Petersa3a3a032000-11-30 05:22:44 +0000492 X, for example.
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000493
494- The mmap.PAGESIZE constant is now initialized using sysconf when
495 possible, which eliminates a dependency on -lucb for Reliant UNIX.
496
497- The md5 file should now compile on all platforms.
498
499- The select module now compiles on platforms that do not define
500 POLLRDNORM and related constants.
501
502- Darwin (Mac OS X): Initial support for static builds on this
Tim Petersa3a3a032000-11-30 05:22:44 +0000503 platform.
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000504
Jeremy Hylton10921202000-10-09 18:34:12 +0000505- BeOS: A number of changes were made to the build and installation
506 process. ar-fake now operates on a directory of object files.
507 dl_export.h is gone, and its macros now appear on the mwcc command
508 line during build on PPC BeOS.
509
Jeremy Hyltond6e20232000-10-16 20:08:38 +0000510- Platform directory in lib/python2.0 is "plat-beos5" (or
Jeremy Hylton10921202000-10-09 18:34:12 +0000511 "plat-beos4", if building on BeOS 4.5), rather than "plat-beos".
Jeremy Hyltoned9e6442000-10-09 18:26:42 +0000512
513- Cygwin: Support for shared libraries, Tkinter, and sockets.
514
515- SunOS 4.1.4_JL: Fix test for directory existence in configure.
516
517Tools and other miscellany
518
519- Removed debugging prints from main used with freeze.
520
Tim Peters46446d62000-10-09 21:19:31 +0000521- IDLE auto-indent no longer crashes when it encounters Unicode
522 characters.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000523
524What's new in 2.0 beta 2 (since beta 1)?
525========================================
526
527Core language, builtins, and interpreter
528
Tim Peters482c0212000-09-26 06:33:09 +0000529- Add support for unbounded ints in %d,i,u,x,X,o formats; for example
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000530 "%d" % 2L**64 == "18446744073709551616".
Jeremy Hylton1b618592000-09-26 05:32:36 +0000531
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000532- Add -h and -V command line options to print the usage message and
533 Python version number and exit immediately.
534
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000535- eval() and exec accept Unicode objects as code parameters.
536
537- getattr() and setattr() now also accept Unicode objects for the
538 attribute name, which are converted to strings using the default
539 encoding before lookup.
540
541- Multiplication on string and Unicode now does proper bounds
542 checking; e.g. 'a' * 65536 * 65536 will raise ValueError, "repeated
543 string is too long."
544
545- Better error message when continue is found in try statement in a
Tim Petersa3a3a032000-11-30 05:22:44 +0000546 loop.
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000547
Jeremy Hylton1b618592000-09-26 05:32:36 +0000548
549Standard library and extensions
550
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000551- array: reverse() method of array now works. buffer_info() now does
Jeremy Hylton1b618592000-09-26 05:32:36 +0000552 argument checking; it still takes no arguments.
553
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000554- asyncore/asynchat: Included most recent version from Sam Rushing.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000555
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000556- cgi: Accept '&' or ';' as separator characters when parsing form data.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000557
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000558- CGIHTTPServer: Now works on Windows (and perhaps even Mac).
Jeremy Hylton1b618592000-09-26 05:32:36 +0000559
560- ConfigParser: When reading the file, options spelled in upper case
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000561 letters are now correctly converted to lowercase.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000562
563- copy: Copy Unicode objects atomically.
564
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000565- cPickle: Fail gracefully when copy_reg can't be imported.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000566
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000567- cStringIO: Implemented readlines() method.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000568
Fred Drake67233bc2000-09-26 16:40:27 +0000569- dbm: Add get() and setdefault() methods to dbm object. Add constant
570 `library' to module that names the library used. Added doc strings
571 and method names to error messages. Uses configure to determine
572 which ndbm.h file to include; Berkeley DB's nbdm and GDBM's ndbm is
573 now available options.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000574
575- distutils: Update to version 0.9.3.
576
577- dl: Add several dl.RTLD_ constants.
578
579- fpectl: Now supported on FreeBSD.
580
581- gc: Add DEBUG_SAVEALL option. When enabled all garbage objects
582 found by the collector will be saved in gc.garbage. This is useful
583 for debugging a program that creates reference cycles.
584
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000585- httplib: Three changes: Restore support for set_debuglevel feature
Jeremy Hylton1b618592000-09-26 05:32:36 +0000586 of HTTP class. Do not close socket on zero-length response. Do not
587 crash when server sends invalid content-length header.
588
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000589- mailbox: Mailbox class conforms better to qmail specifications.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000590
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000591- marshal: When reading a short, sign-extend on platforms where shorts
592 are bigger than 16 bits. When reading a long, repair the unportable
593 sign extension that was being done for 64-bit machines. (It assumed
594 that signed right shift sign-extends.)
595
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000596- operator: Add contains(), invert(), __invert__() as aliases for
597 __contains__(), inv(), and __inv__() respectively.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000598
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000599- os: Add support for popen2() and popen3() on all platforms where
600 fork() exists. (popen4() is still in the works.)
Jeremy Hylton1b618592000-09-26 05:32:36 +0000601
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000602- os: (Windows only:) Add startfile() function that acts like double-
Tim Peters482c0212000-09-26 06:33:09 +0000603 clicking on a file in Explorer (or passing the file name to the
604 DOS "start" command).
Jeremy Hylton1b618592000-09-26 05:32:36 +0000605
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000606- os.path: (Windows, DOS:) Treat trailing colon correctly in
Tim Peters482c0212000-09-26 06:33:09 +0000607 os.path.join. os.path.join("a:", "b") yields "a:b".
Jeremy Hylton1b618592000-09-26 05:32:36 +0000608
609- pickle: Now raises ValueError when an invalid pickle that contains
610 a non-string repr where a string repr was expected. This behavior
611 matches cPickle.
612
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000613- posixfile: Remove broken __del__() method.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000614
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000615- py_compile: support CR+LF line terminators in source file.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000616
617- readline: Does not immediately exit when ^C is hit when readline and
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000618 threads are configured. Adds definition of rl_library_version. (The
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000619 latter addition requires GNU readline 2.2 or later.)
Jeremy Hylton1b618592000-09-26 05:32:36 +0000620
621- rfc822: Domain literals returned by AddrlistClass method
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000622 getdomainliteral() are now properly wrapped in brackets.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000623
624- site: sys.setdefaultencoding() should only be called in case the
Tim Peters482c0212000-09-26 06:33:09 +0000625 standard default encoding ("ascii") is changed. This saves quite a
Jeremy Hylton1b618592000-09-26 05:32:36 +0000626 few cycles during startup since the first call to
627 setdefaultencoding() will initialize the codec registry and the
628 encodings package.
629
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000630- socket: Support for size hint in readlines() method of object returned
631 by makefile().
Jeremy Hylton1b618592000-09-26 05:32:36 +0000632
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000633- sre: Added experimental expand() method to match objects. Does not
Jeremy Hylton625915e2000-10-02 13:43:33 +0000634 use buffer interface on Unicode strings. Does not hang if group id
Jeremy Hylton1b618592000-09-26 05:32:36 +0000635 is followed by whitespace.
636
Tim Petersa3a3a032000-11-30 05:22:44 +0000637- StringIO: Size hint in readlines() is now supported as documented.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000638
639- struct: Check ranges for bytes and shorts.
640
641- urllib: Improved handling of win32 proxy settings. Fixed quote and
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000642 quote_plus functions so that the always encode a comma.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000643
644- Tkinter: Image objects are now guaranteed to have unique ids. Set
645 event.delta to zero if Tk version doesn't support mousewheel.
646 Removed some debugging prints.
647
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000648- UserList: now implements __contains__().
Jeremy Hylton1b618592000-09-26 05:32:36 +0000649
Fred Drake67233bc2000-09-26 16:40:27 +0000650- webbrowser: On Windows, use os.startfile() instead of os.popen(),
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000651 which works around a bug in Norton AntiVirus 2000 that leads directly
652 to a Blue Screen freeze.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000653
654- xml: New version detection code allows PyXML to override standard
655 XML package if PyXML version is greater than 0.6.1.
656
Fred Drake64bb3802000-09-26 16:21:35 +0000657- xml.dom: DOM level 1 support for basic XML. Includes xml.dom.minidom
658 (conventional DOM), and xml.dom.pulldom, which allows building the DOM
659 tree only for nodes which are sufficiently interesting to a specific
660 application. Does not provide the HTML-specific extensions. Still
661 undocumented.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000662
Fred Drake64bb3802000-09-26 16:21:35 +0000663- xml.sax: SAX 2 support for Python, including all the handler
664 interfaces needed to process XML 1.0 compliant XML. Some
665 documentation is already available.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000666
Fred Drake64bb3802000-09-26 16:21:35 +0000667- pyexpat: Renamed to xml.parsers.expat since this is part of the new,
668 packagized XML support.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000669
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000670
Jeremy Hylton1b618592000-09-26 05:32:36 +0000671C API
672
673- Add three new convenience functions for module initialization --
674 PyModule_AddObject(), PyModule_AddIntConstant(), and
675 PyModule_AddStringConstant().
676
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000677- Cleaned up definition of NULL in C source code; all definitions were
Jeremy Hylton1b618592000-09-26 05:32:36 +0000678 removed and add #error to Python.h if NULL isn't defined after
679 #include of stdio.h.
680
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000681- Py_PROTO() macros that were removed in 2.0b1 have been restored for
Jeremy Hylton1b618592000-09-26 05:32:36 +0000682 backwards compatibility (at the source level) with old extensions.
683
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000684- A wrapper API was added for signal() and sigaction(). Instead of
685 either function, always use PyOS_getsig() to get a signal handler
686 and PyOS_setsig() to set one. A new convenience typedef
687 PyOS_sighandler_t is defined for the type of signal handlers.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000688
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000689- Add PyString_AsStringAndSize() function that provides access to the
Jeremy Hylton1b618592000-09-26 05:32:36 +0000690 internal data buffer and size of a string object -- or the default
691 encoded version of a Unicode object.
692
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000693- PyString_Size() and PyString_AsString() accept Unicode objects.
694
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000695- The standard header <limits.h> is now included by Python.h (if it
Fred Drake64bb3802000-09-26 16:21:35 +0000696 exists). INT_MAX and LONG_MAX will always be defined, even if
697 <limits.h> is not available.
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000698
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000699- PyFloat_FromString takes a second argument, pend, that was
700 effectively useless. It is now officially useless but preserved for
701 backwards compatibility. If the pend argument is not NULL, *pend is
702 set to NULL.
703
704- PyObject_GetAttr() and PyObject_SetAttr() now accept Unicode objects
705 for the attribute name. See note on getattr() above.
706
707- A few bug fixes to argument processing for Unicode.
708 PyArg_ParseTupleAndKeywords() now accepts "es#" and "es".
709 PyArg_Parse() special cases "s#" for Unicode objects; it returns a
710 pointer to the default encoded string data instead of to the raw
Tim Petersa3a3a032000-11-30 05:22:44 +0000711 UTF-16.
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000712
713- Py_BuildValue accepts B format (for bgen-generated code).
714
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000715
Jeremy Hylton1b618592000-09-26 05:32:36 +0000716Internals
717
718- On Unix, fix code for finding Python installation directory so that
719 it works when argv[0] is a relative path.
720
Andrew M. Kuchlinga1099be2000-12-15 01:16:43 +0000721- Added a true unicode_internal_encode() function and fixed the
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000722 unicode_internal_decode function() to support Unicode objects directly
Jeremy Hylton1b618592000-09-26 05:32:36 +0000723 rather than by generating a copy of the object.
724
Tim Peters482c0212000-09-26 06:33:09 +0000725- Several of the internal Unicode tables are much smaller now, and
726 the source code should be much friendlier to weaker compilers.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000727
Jeremy Hylton97693b02000-09-26 17:42:51 +0000728- In the garbage collector: Fixed bug in collection of tuples. Fixed
729 bug that caused some instances to be removed from the container set
730 while they were still live. Fixed parsing in gc.set_debug() for
731 platforms where sizeof(long) > sizeof(int).
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000732
733- Fixed refcount problem in instance deallocation that only occurred
734 when Py_REF_DEBUG was defined and Py_TRACE_REFS was not.
735
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000736- On Windows, getpythonregpath is now protected against null data in
737 registry key.
738
739- On Unix, create .pyc/.pyo files with O_EXCL flag to avoid a race
Tim Petersa3a3a032000-11-30 05:22:44 +0000740 condition.
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000741
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000742
Jeremy Hylton1b618592000-09-26 05:32:36 +0000743Build and platform-specific issues
744
745- Better support of GNU Pth via --with-pth configure option.
746
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000747- Python/C API now properly exposed to dynamically-loaded extension
748 modules on Reliant UNIX.
Jeremy Hylton1b618592000-09-26 05:32:36 +0000749
750- Changes for the benefit of SunOS 4.1.4 (really!). mmapmodule.c:
751 Don't define MS_SYNC to be zero when it is undefined. Added missing
752 prototypes in posixmodule.c.
753
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000754- Improved support for HP-UX build. Threads should now be correctly
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000755 configured (on HP-UX 10.20 and 11.00).
Jeremy Hylton1b618592000-09-26 05:32:36 +0000756
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000757- Fix largefile support on older NetBSD systems and OpenBSD by adding
758 define for TELL64.
759
760
761Tools and other miscellany
762
763- ftpmirror: Call to main() is wrapped in if __name__ == "__main__".
764
765- freeze: The modulefinder now works with 2.0 opcodes.
766
Tim Petersa3a3a032000-11-30 05:22:44 +0000767- IDLE:
Jeremy Hyltonfa2e2c12000-09-26 16:31:30 +0000768 Move hackery of sys.argv until after the Tk instance has been
769 created, which allows the application-specific Tkinter
770 initialization to be executed if present; also pass an explicit
771 className parameter to the Tk() constructor.
Fred Drake64bb3802000-09-26 16:21:35 +0000772
Jeremy Hylton1b618592000-09-26 05:32:36 +0000773
774What's new in 2.0 beta 1?
775=========================
776
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000777Source Incompatibilities
778------------------------
779
780None. Note that 1.6 introduced several incompatibilities with 1.5.2,
781such as single-argument append(), connect() and bind(), and changes to
782str(long) and repr(float).
783
784
785Binary Incompatibilities
786------------------------
787
788- Third party extensions built for Python 1.5.x or 1.6 cannot be used
789with Python 2.0; these extensions will have to be rebuilt for Python
7902.0.
791
792- On Windows, attempting to import a third party extension built for
793Python 1.5.x or 1.6 results in an immediate crash; there's not much we
794can do about this. Check your PYTHONPATH environment variable!
795
796- Python bytecode files (*.pyc and *.pyo) are not compatible between
797releases.
798
799
800Overview of Changes Since 1.6
801-----------------------------
802
803There are many new modules (including brand new XML support through
804the xml package, and i18n support through the gettext module); a list
805of all new modules is included below. Lots of bugs have been fixed.
806
Jeremy Hylton24c3d602000-09-05 19:36:26 +0000807The process for making major new changes to the language has changed
808since Python 1.6. Enhancements must now be documented by a Python
809Enhancement Proposal (PEP) before they can be accepted.
810
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000811There are several important syntax enhancements, described in more
812detail below:
813
814 - Augmented assignment, e.g. x += 1
815
816 - List comprehensions, e.g. [x**2 for x in range(10)]
817
818 - Extended import statement, e.g. import Module as Name
819
820 - Extended print statement, e.g. print >> file, "Hello"
821
822Other important changes:
823
824 - Optional collection of cyclical garbage
825
Jeremy Hylton24c3d602000-09-05 19:36:26 +0000826Python Enhancement Proposal (PEP)
827---------------------------------
828
829PEP stands for Python Enhancement Proposal. A PEP is a design
830document providing information to the Python community, or describing
831a new feature for Python. The PEP should provide a concise technical
832specification of the feature and a rationale for the feature.
833
834We intend PEPs to be the primary mechanisms for proposing new
835features, for collecting community input on an issue, and for
836documenting the design decisions that have gone into Python. The PEP
837author is responsible for building consensus within the community and
838documenting dissenting opinions.
839
840The PEPs are available at http://python.sourceforge.net/peps/.
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000841
842Augmented Assignment
843--------------------
844
845This must have been the most-requested feature of the past years!
846Eleven new assignment operators were added:
847
Guido van Rossume905e952000-09-05 12:42:46 +0000848 += -= *= /= %= **= <<= >>= &= ^= |=
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000849
850For example,
851
852 A += B
853
854is similar to
855
856 A = A + B
857
858except that A is evaluated only once (relevant when A is something
859like dict[index].attr).
860
861However, if A is a mutable object, A may be modified in place. Thus,
862if A is a number or a string, A += B has the same effect as A = A+B
863(except A is only evaluated once); but if a is a list, A += B has the
864same effect as A.extend(B)!
865
866Classes and built-in object types can override the new operators in
867order to implement the in-place behavior; the not-in-place behavior is
868used automatically as a fallback when an object doesn't implement the
869in-place behavior. For classes, the method name is derived from the
870method name for the corresponding not-in-place operator by inserting
871an 'i' in front of the name, e.g. __iadd__ implements in-place
872__add__.
873
874Augmented assignment was implemented by Thomas Wouters.
875
876
877List Comprehensions
878-------------------
879
880This is a flexible new notation for lists whose elements are computed
881from another list (or lists). The simplest form is:
882
883 [<expression> for <variable> in <sequence>]
884
Guido van Rossum56db0952000-09-06 23:34:25 +0000885For example, [i**2 for i in range(4)] yields the list [0, 1, 4, 9].
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000886This is more efficient than a for loop with a list.append() call.
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000887
888You can also add a condition:
889
890 [<expression> for <variable> in <sequence> if <condition>]
891
892For example, [w for w in words if w == w.lower()] would yield the list
893of words that contain no uppercase characters. This is more efficient
Guido van Rossumf62ed9c2000-09-26 11:16:10 +0000894than a for loop with an if statement and a list.append() call.
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000895
896You can also have nested for loops and more than one 'if' clause. For
897example, here's a function that flattens a sequence of sequences::
898
899 def flatten(seq):
900 return [x for subseq in seq for x in subseq]
901
902 flatten([[0], [1,2,3], [4,5], [6,7,8,9], []])
903
904This prints
905
906 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
907
908List comprehensions originated as a patch set from Greg Ewing; Skip
Jeremy Hylton24c3d602000-09-05 19:36:26 +0000909Montanaro and Thomas Wouters also contributed. Described by PEP 202.
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000910
911
912Extended Import Statement
913-------------------------
914
915Many people have asked for a way to import a module under a different
916name. This can be accomplished like this:
917
918 import foo
919 bar = foo
920 del foo
921
922but this common idiom gets old quickly. A simple extension of the
923import statement now allows this to be written as follows:
924
925 import foo as bar
926
927There's also a variant for 'from ... import':
928
929 from foo import bar as spam
930
931This also works with packages; e.g. you can write this:
932
933 import test.regrtest as regrtest
934
935Note that 'as' is not a new keyword -- it is recognized only in this
936context (this is only possible because the syntax for the import
937statement doesn't involve expressions).
938
Jeremy Hylton24c3d602000-09-05 19:36:26 +0000939Implemented by Thomas Wouters. Described by PEP 221.
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000940
941
942Extended Print Statement
943------------------------
944
945Easily the most controversial new feature, this extension to the print
946statement adds an option to make the output go to a different file
947than the default sys.stdout.
948
949For example, to write an error message to sys.stderr, you can now
950write:
951
952 print >> sys.stderr, "Error: bad dog!"
953
954As a special feature, if the expression used to indicate the file
Fred Drake45888ff2000-09-29 17:09:11 +0000955evaluates to None, the current value of sys.stdout is used. Thus:
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000956
957 print >> None, "Hello world"
958
959is equivalent to
960
961 print "Hello world"
962
Jeremy Hylton24c3d602000-09-05 19:36:26 +0000963Design and implementation by Barry Warsaw. Described by PEP 214.
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000964
965
966Optional Collection of Cyclical Garbage
967---------------------------------------
968
969Python is now equipped with a garbage collector that can hunt down
970cyclical references between Python objects. It's no replacement for
971reference counting; in fact, it depends on the reference counts being
972correct, and decides that a set of objects belong to a cycle if all
973their reference counts can be accounted for from their references to
974each other. This devious scheme was first proposed by Eric Tiedemann,
975and brought to implementation by Neil Schemenauer.
976
977There's a module "gc" that lets you control some parameters of the
978garbage collection. There's also an option to the configure script
979that lets you enable or disable the garbage collection. In 2.0b1,
980it's on by default, so that we (hopefully) can collect decent user
981experience with this new feature. There are some questions about its
Fred Drake9f11cf82000-09-29 17:54:40 +0000982performance. If it proves to be too much of a problem, we'll turn it
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000983off by default in the final 2.0 release.
984
985
986Smaller Changes
987---------------
988
989A new function zip() was added. zip(seq1, seq2, ...) is equivalent to
990map(None, seq1, seq2, ...) when the sequences have the same length;
991i.e. zip([1,2,3], [10,20,30]) returns [(1,10), (2,20), (3,30)]. When
992the lists are not all the same length, the shortest list wins:
Jeremy Hylton24c3d602000-09-05 19:36:26 +0000993zip([1,2,3], [10,20]) returns [(1,10), (2,20)]. See PEP 201.
Guido van Rossumf2ffce02000-09-05 04:38:34 +0000994
995sys.version_info is a tuple (major, minor, micro, level, serial).
996
997Dictionaries have an odd new method, setdefault(key, default).
998dict.setdefault(key, default) returns dict[key] if it exists; if not,
999it sets dict[key] to default and returns that value. Thus:
1000
1001 dict.setdefault(key, []).append(item)
1002
1003does the same work as this common idiom:
1004
1005 if not dict.has_key(key):
1006 dict[key] = []
1007 dict[key].append(item)
1008
Jeremy Hylton24c3d602000-09-05 19:36:26 +00001009There are two new variants of SyntaxError that are raised for
1010indentation-related errors: IndentationError and TabError.
1011
1012Changed \x to consume exactly two hex digits; see PEP 223. Added \U
1013escape that consumes exactly eight hex digits.
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001014
1015The limits on the size of expressions and file in Python source code
1016have been raised from 2**16 to 2**32. Previous versions of Python
1017were limited because the maximum argument size the Python VM accepted
1018was 2**16. This limited the size of object constructor expressions,
1019e.g. [1,2,3] or {'a':1, 'b':2}, and the size of source files. This
1020limit was raised thanks to a patch by Charles Waldman that effectively
1021fixes the problem. It is now much more likely that you will be
1022limited by available memory than by an arbitrary limit in Python.
1023
1024The interpreter's maximum recursion depth can be modified by Python
1025programs using sys.getrecursionlimit and sys.setrecursionlimit. This
1026limit is the maximum number of recursive calls that can be made by
1027Python code. The limit exists to prevent infinite recursion from
1028overflowing the C stack and causing a core dump. The default value is
10291000. The maximum safe value for a particular platform can be found
1030by running Misc/find_recursionlimit.py.
Guido van Rossumf2ffce02000-09-05 04:38:34 +00001031
1032New Modules and Packages
1033------------------------
1034
1035atexit - for registering functions to be called when Python exits.
1036
1037imputil - Greg Stein's alternative API for writing custom import
1038hooks.
1039
1040pyexpat - an interface to the Expat XML parser, contributed by Paul
1041Prescod.
1042
1043xml - a new package with XML support code organized (so far) in three
1044subpackages: xml.dom, xml.sax, and xml.parsers. Describing these
1045would fill a volume. There's a special feature whereby a
1046user-installed package named _xmlplus overrides the standard
1047xmlpackage; this is intended to give the XML SIG a hook to distribute
1048backwards-compatible updates to the standard xml package.
1049
1050webbrowser - a platform-independent API to launch a web browser.
1051
1052
Guido van Rossume905e952000-09-05 12:42:46 +00001053Changed Modules
1054---------------
1055
Jeremy Hylton24c3d602000-09-05 19:36:26 +00001056array -- new methods for array objects: count, extend, index, pop, and
1057remove
1058
1059binascii -- new functions b2a_hex and a2b_hex that convert between
1060binary data and its hex representation
1061
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001062calendar -- Many new functions that support features including control
1063over which day of the week is the first day, returning strings instead
1064of printing them. Also new symbolic constants for days of week,
1065e.g. MONDAY, ..., SUNDAY.
1066
1067cgi -- FieldStorage objects have a getvalue method that works like a
1068dictionary's get method and returns the value attribute of the object.
1069
1070ConfigParser -- The parser object has new methods has_option,
1071remove_section, remove_option, set, and write. They allow the module
1072to be used for writing config files as well as reading them.
1073
1074ftplib -- ntransfercmd(), transfercmd(), and retrbinary() all now
Guido van Rossume905e952000-09-05 12:42:46 +00001075optionally support the RFC 959 REST command.
1076
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001077gzip -- readline and readlines now accept optional size arguments
Guido van Rossume905e952000-09-05 12:42:46 +00001078
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001079httplib -- New interfaces and support for HTTP/1.1 by Greg Stein. See
1080the module doc strings for details.
Guido van Rossum830ca2a2000-09-05 15:34:16 +00001081
Jeremy Hylton24c3d602000-09-05 19:36:26 +00001082locale -- implement getdefaultlocale for Win32 and Macintosh
1083
1084marshal -- no longer dumps core when marshaling deeply nested or
1085recursive data structures
1086
1087os -- new functions isatty, seteuid, setegid, setreuid, setregid
1088
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001089os/popen2 -- popen2/popen3/popen4 support under Windows. popen2/popen3
1090support under Unix.
1091
Jeremy Hylton24c3d602000-09-05 19:36:26 +00001092os/pty -- support for openpty and forkpty
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001093
1094os.path -- fix semantics of os.path.commonprefix
1095
1096smtplib -- support for sending very long messages
1097
1098socket -- new function getfqdn()
1099
1100readline -- new functions to read, write and truncate history files.
1101The readline section of the library reference manual contains an
1102example.
1103
Jeremy Hylton24c3d602000-09-05 19:36:26 +00001104select -- add interface to poll system call
1105
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001106shutil -- new copyfileobj function
1107
1108SimpleHTTPServer, CGIHTTPServer -- Fix problems with buffering in the
1109HTTP server.
1110
Jeremy Hylton24c3d602000-09-05 19:36:26 +00001111Tkinter -- optimization of function flatten
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001112
1113urllib -- scans environment variables for proxy configuration,
Tim Peters8b092332000-09-05 20:15:25 +00001114e.g. http_proxy.
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001115
1116whichdb -- recognizes dumbdbm format
Guido van Rossume905e952000-09-05 12:42:46 +00001117
1118
1119Obsolete Modules
1120----------------
1121
1122None. However note that 1.6 made a whole slew of modules obsolete:
1123stdwin, soundex, cml, cmpcache, dircache, dump, find, grep, packmail,
1124poly, zmod, strop, util, whatsound.
1125
1126
1127Changed, New, Obsolete Tools
1128----------------------------
1129
Tim Peters8b092332000-09-05 20:15:25 +00001130None.
Guido van Rossume905e952000-09-05 12:42:46 +00001131
1132
Guido van Rossumf2ffce02000-09-05 04:38:34 +00001133C-level Changes
1134---------------
1135
1136Several cleanup jobs were carried out throughout the source code.
1137
1138All C code was converted to ANSI C; we got rid of all uses of the
1139Py_PROTO() macro, which makes the header files a lot more readable.
1140
1141Most of the portability hacks were moved to a new header file,
1142pyport.h; several other new header files were added and some old
1143header files were removed, in an attempt to create a more rational set
1144of header files. (Few of these ever need to be included explicitly;
1145they are all included by Python.h.)
1146
Guido van Rossumf2ffce02000-09-05 04:38:34 +00001147Trent Mick ensured portability to 64-bit platforms, under both Linux
Jeremy Hylton24c3d602000-09-05 19:36:26 +00001148and Win64, especially for the new Intel Itanium processor. Mick also
1149added large file support for Linux64 and Win64.
Guido van Rossumf2ffce02000-09-05 04:38:34 +00001150
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001151The C APIs to return an object's size have been update to consistently
1152use the form PyXXX_Size, e.g. PySequence_Size and PyDict_Size. In
1153previous versions, the abstract interfaces used PyXXX_Length and the
1154concrete interfaces used PyXXX_Size. The old names,
1155e.g. PyObject_Length, are still available for backwards compatibility
1156at the API level, but are deprecated.
1157
Jeremy Hylton24c3d602000-09-05 19:36:26 +00001158The PyOS_CheckStack function has been implemented on Windows by
1159Fredrik Lundh. It prevents Python from failing with a stack overflow
1160on Windows.
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001161
1162The GC changes resulted in creation of two new slots on object,
1163tp_traverse and tp_clear. The augmented assignment changes result in
Guido van Rossum4338a282000-09-06 13:02:08 +00001164the creation of a new slot for each in-place operator.
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001165
1166The GC API creates new requirements for container types implemented in
Guido van Rossum4338a282000-09-06 13:02:08 +00001167C extension modules. See Include/objimpl.h for details.
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001168
Jeremy Hylton24c3d602000-09-05 19:36:26 +00001169PyErr_Format has been updated to automatically calculate the size of
1170the buffer needed to hold the formatted result string. This change
1171prevents crashes caused by programmer error.
Jeremy Hyltonbdebd542000-09-05 18:28:54 +00001172
Jeremy Hylton24c3d602000-09-05 19:36:26 +00001173New C API calls: PyObject_AsFileDescriptor, PyErr_WriteUnraisable.
Guido van Rossume905e952000-09-05 12:42:46 +00001174
Jeremy Hylton24c3d602000-09-05 19:36:26 +00001175PyRun_AnyFileEx, PyRun_SimpleFileEx, PyRun_FileEx -- New functions
1176that are the same as their non-Ex counterparts except they take an
1177extra flag argument that tells them to close the file when done.
1178
1179XXX There were other API changes that should be fleshed out here.
Guido van Rossumab9d6f01998-08-10 22:01:13 +00001180
Tim Peters8b092332000-09-05 20:15:25 +00001181
1182Windows Changes
1183---------------
1184
1185New popen2/popen3/peopen4 in os module (see Changed Modules above).
1186
1187os.popen is much more usable on Windows 95 and 98. See Microsoft
1188Knowledge Base article Q150956. The Win9x workaround described there
1189is implemented by the new w9xpopen.exe helper in the root of your
1190Python installation. Note that Python uses this internally; it is not
1191a standalone program.
1192
1193Administrator privileges are no longer required to install Python
1194on Windows NT or Windows 2000. If you have administrator privileges,
1195Python's registry info will be written under HKEY_LOCAL_MACHINE.
1196Otherwise the installer backs off to writing Python's registry info
Guido van Rossum4338a282000-09-06 13:02:08 +00001197under HKEY_CURRENT_USER. The latter is sufficient for all "normal"
Tim Peters8b092332000-09-05 20:15:25 +00001198uses of Python, but will prevent some advanced uses from working
1199(for example, running a Python script as an NT service, or possibly
1200from CGI).
1201
1202[This was new in 1.6] The installer no longer runs a separate Tcl/Tk
1203installer; instead, it installs the needed Tcl/Tk files directly in the
1204Python directory. If you already have a Tcl/Tk installation, this
1205wastes some disk space (about 4 Megs) but avoids problems with
1206conflicting Tcl/Tk installations, and makes it much easier for Python
1207to ensure that Tcl/Tk can find all its files.
1208
1209[This was new in 1.6] The Windows installer now installs by default in
1210\Python20\ on the default volume, instead of \Program Files\Python-2.0\.
1211
Guido van Rossumf62ed9c2000-09-26 11:16:10 +00001212
1213Updates to the changes between 1.5.2 and 1.6
1214--------------------------------------------
1215
1216The 1.6 NEWS file can't be changed after the release is done, so here
1217is some late-breaking news:
1218
1219New APIs in locale.py: normalize(), getdefaultlocale(), resetlocale(),
1220and changes to getlocale() and setlocale().
1221
1222The new module is now enabled per default.
1223
1224It is not true that the encodings codecs cannot be used for normal
1225strings: the string.encode() (which is also present on 8-bit strings
1226!) allows using them for 8-bit strings too, e.g. to convert files from
1227cp1252 (Windows) to latin-1 or vice-versa.
1228
1229Japanese codecs are available from Tamito KAJIYAMA:
1230http://pseudo.grad.sccs.chukyo-u.ac.jp/~kajiyama/python/
1231
1232
Guido van Rossumab9d6f01998-08-10 22:01:13 +00001233======================================================================