PageRenderTime 511ms CodeModel.GetById 101ms app.highlight 183ms RepoModel.GetById 158ms app.codeStats 1ms

/Doc/whatsnew/2.3.rst

http://unladen-swallow.googlecode.com/
ReStructuredText | 2078 lines | 1595 code | 483 blank | 0 comment | 0 complexity | 8db9b7b78675d404b6b3341c06d9e9af MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1****************************
   2  What's New in Python 2.3
   3****************************
   4
   5:Author: A.M. Kuchling
   6
   7.. |release| replace:: 1.01
   8
   9.. $Id: whatsnew23.tex 54631 2007-03-31 11:58:36Z georg.brandl $
  10
  11This article explains the new features in Python 2.3.  Python 2.3 was released
  12on July 29, 2003.
  13
  14The main themes for Python 2.3 are polishing some of the features added in 2.2,
  15adding various small but useful enhancements to the core language, and expanding
  16the standard library.  The new object model introduced in the previous version
  17has benefited from 18 months of bugfixes and from optimization efforts that have
  18improved the performance of new-style classes.  A few new built-in functions
  19have been added such as :func:`sum` and :func:`enumerate`.  The :keyword:`in`
  20operator can now be used for substring searches (e.g. ``"ab" in "abc"`` returns
  21:const:`True`).
  22
  23Some of the many new library features include Boolean, set, heap, and date/time
  24data types, the ability to import modules from ZIP-format archives, metadata
  25support for the long-awaited Python catalog, an updated version of IDLE, and
  26modules for logging messages, wrapping text, parsing CSV files, processing
  27command-line options, using BerkeleyDB databases...  the list of new and
  28enhanced modules is lengthy.
  29
  30This article doesn't attempt to provide a complete specification of the new
  31features, but instead provides a convenient overview.  For full details, you
  32should refer to the documentation for Python 2.3, such as the Python Library
  33Reference and the Python Reference Manual.  If you want to understand the
  34complete implementation and design rationale, refer to the PEP for a particular
  35new feature.
  36
  37.. ======================================================================
  38
  39
  40PEP 218: A Standard Set Datatype
  41================================
  42
  43The new :mod:`sets` module contains an implementation of a set datatype.  The
  44:class:`Set` class is for mutable sets, sets that can have members added and
  45removed.  The :class:`ImmutableSet` class is for sets that can't be modified,
  46and instances of :class:`ImmutableSet` can therefore be used as dictionary keys.
  47Sets are built on top of dictionaries, so the elements within a set must be
  48hashable.
  49
  50Here's a simple example::
  51
  52   >>> import sets
  53   >>> S = sets.Set([1,2,3])
  54   >>> S
  55   Set([1, 2, 3])
  56   >>> 1 in S
  57   True
  58   >>> 0 in S
  59   False
  60   >>> S.add(5)
  61   >>> S.remove(3)
  62   >>> S
  63   Set([1, 2, 5])
  64   >>>
  65
  66The union and intersection of sets can be computed with the :meth:`union` and
  67:meth:`intersection` methods; an alternative notation uses the bitwise operators
  68``&`` and ``|``. Mutable sets also have in-place versions of these methods,
  69:meth:`union_update` and :meth:`intersection_update`. ::
  70
  71   >>> S1 = sets.Set([1,2,3])
  72   >>> S2 = sets.Set([4,5,6])
  73   >>> S1.union(S2)
  74   Set([1, 2, 3, 4, 5, 6])
  75   >>> S1 | S2                  # Alternative notation
  76   Set([1, 2, 3, 4, 5, 6])
  77   >>> S1.intersection(S2)
  78   Set([])
  79   >>> S1 & S2                  # Alternative notation
  80   Set([])
  81   >>> S1.union_update(S2)
  82   >>> S1
  83   Set([1, 2, 3, 4, 5, 6])
  84   >>>
  85
  86It's also possible to take the symmetric difference of two sets.  This is the
  87set of all elements in the union that aren't in the intersection.  Another way
  88of putting it is that the symmetric difference contains all elements that are in
  89exactly one set.  Again, there's an alternative notation (``^``), and an in-
  90place version with the ungainly name :meth:`symmetric_difference_update`. ::
  91
  92   >>> S1 = sets.Set([1,2,3,4])
  93   >>> S2 = sets.Set([3,4,5,6])
  94   >>> S1.symmetric_difference(S2)
  95   Set([1, 2, 5, 6])
  96   >>> S1 ^ S2
  97   Set([1, 2, 5, 6])
  98   >>>
  99
 100There are also :meth:`issubset` and :meth:`issuperset` methods for checking
 101whether one set is a subset or superset of another::
 102
 103   >>> S1 = sets.Set([1,2,3])
 104   >>> S2 = sets.Set([2,3])
 105   >>> S2.issubset(S1)
 106   True
 107   >>> S1.issubset(S2)
 108   False
 109   >>> S1.issuperset(S2)
 110   True
 111   >>>
 112
 113
 114.. seealso::
 115
 116   :pep:`218` - Adding a Built-In Set Object Type
 117      PEP written by Greg V. Wilson. Implemented by Greg V. Wilson, Alex Martelli, and
 118      GvR.
 119
 120.. ======================================================================
 121
 122
 123.. _section-generators:
 124
 125PEP 255: Simple Generators
 126==========================
 127
 128In Python 2.2, generators were added as an optional feature, to be enabled by a
 129``from __future__ import generators`` directive.  In 2.3 generators no longer
 130need to be specially enabled, and are now always present; this means that
 131:keyword:`yield` is now always a keyword.  The rest of this section is a copy of
 132the description of generators from the "What's New in Python 2.2" document; if
 133you read it back when Python 2.2 came out, you can skip the rest of this
 134section.
 135
 136You're doubtless familiar with how function calls work in Python or C. When you
 137call a function, it gets a private namespace where its local variables are
 138created.  When the function reaches a :keyword:`return` statement, the local
 139variables are destroyed and the resulting value is returned to the caller.  A
 140later call to the same function will get a fresh new set of local variables.
 141But, what if the local variables weren't thrown away on exiting a function?
 142What if you could later resume the function where it left off?  This is what
 143generators provide; they can be thought of as resumable functions.
 144
 145Here's the simplest example of a generator function::
 146
 147   def generate_ints(N):
 148       for i in range(N):
 149           yield i
 150
 151A new keyword, :keyword:`yield`, was introduced for generators.  Any function
 152containing a :keyword:`yield` statement is a generator function; this is
 153detected by Python's bytecode compiler which compiles the function specially as
 154a result.
 155
 156When you call a generator function, it doesn't return a single value; instead it
 157returns a generator object that supports the iterator protocol.  On executing
 158the :keyword:`yield` statement, the generator outputs the value of ``i``,
 159similar to a :keyword:`return` statement.  The big difference between
 160:keyword:`yield` and a :keyword:`return` statement is that on reaching a
 161:keyword:`yield` the generator's state of execution is suspended and local
 162variables are preserved.  On the next call to the generator's ``.next()``
 163method, the function will resume executing immediately after the
 164:keyword:`yield` statement.  (For complicated reasons, the :keyword:`yield`
 165statement isn't allowed inside the :keyword:`try` block of a :keyword:`try`...\
 166:keyword:`finally` statement; read :pep:`255` for a full explanation of the
 167interaction between :keyword:`yield` and exceptions.)
 168
 169Here's a sample usage of the :func:`generate_ints` generator::
 170
 171   >>> gen = generate_ints(3)
 172   >>> gen
 173   <generator object at 0x8117f90>
 174   >>> gen.next()
 175   0
 176   >>> gen.next()
 177   1
 178   >>> gen.next()
 179   2
 180   >>> gen.next()
 181   Traceback (most recent call last):
 182     File "stdin", line 1, in ?
 183     File "stdin", line 2, in generate_ints
 184   StopIteration
 185
 186You could equally write ``for i in generate_ints(5)``, or ``a,b,c =
 187generate_ints(3)``.
 188
 189Inside a generator function, the :keyword:`return` statement can only be used
 190without a value, and signals the end of the procession of values; afterwards the
 191generator cannot return any further values. :keyword:`return` with a value, such
 192as ``return 5``, is a syntax error inside a generator function.  The end of the
 193generator's results can also be indicated by raising :exc:`StopIteration`
 194manually, or by just letting the flow of execution fall off the bottom of the
 195function.
 196
 197You could achieve the effect of generators manually by writing your own class
 198and storing all the local variables of the generator as instance variables.  For
 199example, returning a list of integers could be done by setting ``self.count`` to
 2000, and having the :meth:`next` method increment ``self.count`` and return it.
 201However, for a moderately complicated generator, writing a corresponding class
 202would be much messier. :file:`Lib/test/test_generators.py` contains a number of
 203more interesting examples.  The simplest one implements an in-order traversal of
 204a tree using generators recursively. ::
 205
 206   # A recursive generator that generates Tree leaves in in-order.
 207   def inorder(t):
 208       if t:
 209           for x in inorder(t.left):
 210               yield x
 211           yield t.label
 212           for x in inorder(t.right):
 213               yield x
 214
 215Two other examples in :file:`Lib/test/test_generators.py` produce solutions for
 216the N-Queens problem (placing $N$ queens on an $NxN$ chess board so that no
 217queen threatens another) and the Knight's Tour (a route that takes a knight to
 218every square of an $NxN$ chessboard without visiting any square twice).
 219
 220The idea of generators comes from other programming languages, especially Icon
 221(http://www.cs.arizona.edu/icon/), where the idea of generators is central.  In
 222Icon, every expression and function call behaves like a generator.  One example
 223from "An Overview of the Icon Programming Language" at
 224http://www.cs.arizona.edu/icon/docs/ipd266.htm gives an idea of what this looks
 225like::
 226
 227   sentence := "Store it in the neighboring harbor"
 228   if (i := find("or", sentence)) > 5 then write(i)
 229
 230In Icon the :func:`find` function returns the indexes at which the substring
 231"or" is found: 3, 23, 33.  In the :keyword:`if` statement, ``i`` is first
 232assigned a value of 3, but 3 is less than 5, so the comparison fails, and Icon
 233retries it with the second value of 23.  23 is greater than 5, so the comparison
 234now succeeds, and the code prints the value 23 to the screen.
 235
 236Python doesn't go nearly as far as Icon in adopting generators as a central
 237concept.  Generators are considered part of the core Python language, but
 238learning or using them isn't compulsory; if they don't solve any problems that
 239you have, feel free to ignore them. One novel feature of Python's interface as
 240compared to Icon's is that a generator's state is represented as a concrete
 241object (the iterator) that can be passed around to other functions or stored in
 242a data structure.
 243
 244
 245.. seealso::
 246
 247   :pep:`255` - Simple Generators
 248      Written by Neil Schemenauer, Tim Peters, Magnus Lie Hetland.  Implemented mostly
 249      by Neil Schemenauer and Tim Peters, with other fixes from the Python Labs crew.
 250
 251.. ======================================================================
 252
 253
 254.. _section-encodings:
 255
 256PEP 263: Source Code Encodings
 257==============================
 258
 259Python source files can now be declared as being in different character set
 260encodings.  Encodings are declared by including a specially formatted comment in
 261the first or second line of the source file.  For example, a UTF-8 file can be
 262declared with::
 263
 264   #!/usr/bin/env python
 265   # -*- coding: UTF-8 -*-
 266
 267Without such an encoding declaration, the default encoding used is 7-bit ASCII.
 268Executing or importing modules that contain string literals with 8-bit
 269characters and have no encoding declaration will result in a
 270:exc:`DeprecationWarning` being signalled by Python 2.3; in 2.4 this will be a
 271syntax error.
 272
 273The encoding declaration only affects Unicode string literals, which will be
 274converted to Unicode using the specified encoding.  Note that Python identifiers
 275are still restricted to ASCII characters, so you can't have variable names that
 276use characters outside of the usual alphanumerics.
 277
 278
 279.. seealso::
 280
 281   :pep:`263` - Defining Python Source Code Encodings
 282      Written by Marc-André Lemburg and Martin von Löwis; implemented by Suzuki Hisao
 283      and Martin von Löwis.
 284
 285.. ======================================================================
 286
 287
 288PEP 273: Importing Modules from ZIP Archives
 289============================================
 290
 291The new :mod:`zipimport` module adds support for importing modules from a ZIP-
 292format archive.  You don't need to import the module explicitly; it will be
 293automatically imported if a ZIP archive's filename is added to ``sys.path``.
 294For example::
 295
 296   amk@nyman:~/src/python$ unzip -l /tmp/example.zip
 297   Archive:  /tmp/example.zip
 298     Length     Date   Time    Name
 299    --------    ----   ----    ----
 300        8467  11-26-02 22:30   jwzthreading.py
 301    --------                   -------
 302        8467                   1 file
 303   amk@nyman:~/src/python$ ./python
 304   Python 2.3 (#1, Aug 1 2003, 19:54:32)
 305   >>> import sys
 306   >>> sys.path.insert(0, '/tmp/example.zip')  # Add .zip file to front of path
 307   >>> import jwzthreading
 308   >>> jwzthreading.__file__
 309   '/tmp/example.zip/jwzthreading.py'
 310   >>>
 311
 312An entry in ``sys.path`` can now be the filename of a ZIP archive. The ZIP
 313archive can contain any kind of files, but only files named :file:`\*.py`,
 314:file:`\*.pyc`, or :file:`\*.pyo` can be imported.  If an archive only contains
 315:file:`\*.py` files, Python will not attempt to modify the archive by adding the
 316corresponding :file:`\*.pyc` file, meaning that if a ZIP archive doesn't contain
 317:file:`\*.pyc` files, importing may be rather slow.
 318
 319A path within the archive can also be specified to only import from a
 320subdirectory; for example, the path :file:`/tmp/example.zip/lib/` would only
 321import from the :file:`lib/` subdirectory within the archive.
 322
 323
 324.. seealso::
 325
 326   :pep:`273` - Import Modules from Zip Archives
 327      Written by James C. Ahlstrom,  who also provided an implementation. Python 2.3
 328      follows the specification in :pep:`273`,  but uses an implementation written by
 329      Just van Rossum  that uses the import hooks described in :pep:`302`. See section
 330      :ref:`section-pep302` for a description of the new import hooks.
 331
 332.. ======================================================================
 333
 334
 335PEP 277: Unicode file name support for Windows NT
 336=================================================
 337
 338On Windows NT, 2000, and XP, the system stores file names as Unicode strings.
 339Traditionally, Python has represented file names as byte strings, which is
 340inadequate because it renders some file names inaccessible.
 341
 342Python now allows using arbitrary Unicode strings (within the limitations of the
 343file system) for all functions that expect file names, most notably the
 344:func:`open` built-in function. If a Unicode string is passed to
 345:func:`os.listdir`, Python now returns a list of Unicode strings.  A new
 346function, :func:`os.getcwdu`, returns the current directory as a Unicode string.
 347
 348Byte strings still work as file names, and on Windows Python will transparently
 349convert them to Unicode using the ``mbcs`` encoding.
 350
 351Other systems also allow Unicode strings as file names but convert them to byte
 352strings before passing them to the system, which can cause a :exc:`UnicodeError`
 353to be raised. Applications can test whether arbitrary Unicode strings are
 354supported as file names by checking :attr:`os.path.supports_unicode_filenames`,
 355a Boolean value.
 356
 357Under MacOS, :func:`os.listdir` may now return Unicode filenames.
 358
 359
 360.. seealso::
 361
 362   :pep:`277` - Unicode file name support for Windows NT
 363      Written by Neil Hodgson; implemented by Neil Hodgson, Martin von Löwis, and Mark
 364      Hammond.
 365
 366.. ======================================================================
 367
 368
 369PEP 278: Universal Newline Support
 370==================================
 371
 372The three major operating systems used today are Microsoft Windows, Apple's
 373Macintosh OS, and the various Unix derivatives.  A minor irritation of cross-
 374platform work  is that these three platforms all use different characters to
 375mark the ends of lines in text files.  Unix uses the linefeed (ASCII character
 37610), MacOS uses the carriage return (ASCII character 13), and Windows uses a
 377two-character sequence of a carriage return plus a newline.
 378
 379Python's file objects can now support end of line conventions other than the one
 380followed by the platform on which Python is running. Opening a file with the
 381mode ``'U'`` or ``'rU'`` will open a file for reading in universal newline mode.
 382All three line ending conventions will be translated to a ``'\n'`` in the
 383strings returned by the various file methods such as :meth:`read` and
 384:meth:`readline`.
 385
 386Universal newline support is also used when importing modules and when executing
 387a file with the :func:`execfile` function.  This means that Python modules can
 388be shared between all three operating systems without needing to convert the
 389line-endings.
 390
 391This feature can be disabled when compiling Python by specifying the
 392:option:`--without-universal-newlines` switch when running Python's
 393:program:`configure` script.
 394
 395
 396.. seealso::
 397
 398   :pep:`278` - Universal Newline Support
 399      Written and implemented by Jack Jansen.
 400
 401.. ======================================================================
 402
 403
 404.. _section-enumerate:
 405
 406PEP 279: enumerate()
 407====================
 408
 409A new built-in function, :func:`enumerate`, will make certain loops a bit
 410clearer.  ``enumerate(thing)``, where *thing* is either an iterator or a
 411sequence, returns a iterator that will return ``(0, thing[0])``, ``(1,
 412thing[1])``, ``(2, thing[2])``, and so forth.
 413
 414A common idiom to change every element of a list looks like this::
 415
 416   for i in range(len(L)):
 417       item = L[i]
 418       # ... compute some result based on item ...
 419       L[i] = result
 420
 421This can be rewritten using :func:`enumerate` as::
 422
 423   for i, item in enumerate(L):
 424       # ... compute some result based on item ...
 425       L[i] = result
 426
 427
 428.. seealso::
 429
 430   :pep:`279` - The enumerate() built-in function
 431      Written and implemented by Raymond D. Hettinger.
 432
 433.. ======================================================================
 434
 435
 436PEP 282: The logging Package
 437============================
 438
 439A standard package for writing logs, :mod:`logging`, has been added to Python
 4402.3.  It provides a powerful and flexible mechanism for generating logging
 441output which can then be filtered and processed in various ways.  A
 442configuration file written in a standard format can be used to control the
 443logging behavior of a program.  Python includes handlers that will write log
 444records to standard error or to a file or socket, send them to the system log,
 445or even e-mail them to a particular address; of course, it's also possible to
 446write your own handler classes.
 447
 448The :class:`Logger` class is the primary class. Most application code will deal
 449with one or more :class:`Logger` objects, each one used by a particular
 450subsystem of the application. Each :class:`Logger` is identified by a name, and
 451names are organized into a hierarchy using ``.``  as the component separator.
 452For example, you might have :class:`Logger` instances named ``server``,
 453``server.auth`` and ``server.network``.  The latter two instances are below
 454``server`` in the hierarchy.  This means that if you turn up the verbosity for
 455``server`` or direct ``server`` messages to a different handler, the changes
 456will also apply to records logged to ``server.auth`` and ``server.network``.
 457There's also a root :class:`Logger` that's the parent of all other loggers.
 458
 459For simple uses, the :mod:`logging` package contains some convenience functions
 460that always use the root log::
 461
 462   import logging
 463
 464   logging.debug('Debugging information')
 465   logging.info('Informational message')
 466   logging.warning('Warning:config file %s not found', 'server.conf')
 467   logging.error('Error occurred')
 468   logging.critical('Critical error -- shutting down')
 469
 470This produces the following output::
 471
 472   WARNING:root:Warning:config file server.conf not found
 473   ERROR:root:Error occurred
 474   CRITICAL:root:Critical error -- shutting down
 475
 476In the default configuration, informational and debugging messages are
 477suppressed and the output is sent to standard error.  You can enable the display
 478of informational and debugging messages by calling the :meth:`setLevel` method
 479on the root logger.
 480
 481Notice the :func:`warning` call's use of string formatting operators; all of the
 482functions for logging messages take the arguments ``(msg, arg1, arg2, ...)`` and
 483log the string resulting from ``msg % (arg1, arg2, ...)``.
 484
 485There's also an :func:`exception` function that records the most recent
 486traceback.  Any of the other functions will also record the traceback if you
 487specify a true value for the keyword argument *exc_info*. ::
 488
 489   def f():
 490       try:    1/0
 491       except: logging.exception('Problem recorded')
 492
 493   f()
 494
 495This produces the following output::
 496
 497   ERROR:root:Problem recorded
 498   Traceback (most recent call last):
 499     File "t.py", line 6, in f
 500       1/0
 501   ZeroDivisionError: integer division or modulo by zero
 502
 503Slightly more advanced programs will use a logger other than the root logger.
 504The :func:`getLogger(name)` function is used to get a particular log, creating
 505it if it doesn't exist yet. :func:`getLogger(None)` returns the root logger. ::
 506
 507   log = logging.getLogger('server')
 508    ...
 509   log.info('Listening on port %i', port)
 510    ...
 511   log.critical('Disk full')
 512    ...
 513
 514Log records are usually propagated up the hierarchy, so a message logged to
 515``server.auth`` is also seen by ``server`` and ``root``, but a :class:`Logger`
 516can prevent this by setting its :attr:`propagate` attribute to :const:`False`.
 517
 518There are more classes provided by the :mod:`logging` package that can be
 519customized.  When a :class:`Logger` instance is told to log a message, it
 520creates a :class:`LogRecord` instance that is sent to any number of different
 521:class:`Handler` instances.  Loggers and handlers can also have an attached list
 522of filters, and each filter can cause the :class:`LogRecord` to be ignored or
 523can modify the record before passing it along.  When they're finally output,
 524:class:`LogRecord` instances are converted to text by a :class:`Formatter`
 525class.  All of these classes can be replaced by your own specially-written
 526classes.
 527
 528With all of these features the :mod:`logging` package should provide enough
 529flexibility for even the most complicated applications.  This is only an
 530incomplete overview of its features, so please see the package's reference
 531documentation for all of the details.  Reading :pep:`282` will also be helpful.
 532
 533
 534.. seealso::
 535
 536   :pep:`282` - A Logging System
 537      Written by Vinay Sajip and Trent Mick; implemented by Vinay Sajip.
 538
 539.. ======================================================================
 540
 541
 542.. _section-bool:
 543
 544PEP 285: A Boolean Type
 545=======================
 546
 547A Boolean type was added to Python 2.3.  Two new constants were added to the
 548:mod:`__builtin__` module, :const:`True` and :const:`False`.  (:const:`True` and
 549:const:`False` constants were added to the built-ins in Python 2.2.1, but the
 5502.2.1 versions are simply set to integer values of 1 and 0 and aren't a
 551different type.)
 552
 553The type object for this new type is named :class:`bool`; the constructor for it
 554takes any Python value and converts it to :const:`True` or :const:`False`. ::
 555
 556   >>> bool(1)
 557   True
 558   >>> bool(0)
 559   False
 560   >>> bool([])
 561   False
 562   >>> bool( (1,) )
 563   True
 564
 565Most of the standard library modules and built-in functions have been changed to
 566return Booleans. ::
 567
 568   >>> obj = []
 569   >>> hasattr(obj, 'append')
 570   True
 571   >>> isinstance(obj, list)
 572   True
 573   >>> isinstance(obj, tuple)
 574   False
 575
 576Python's Booleans were added with the primary goal of making code clearer.  For
 577example, if you're reading a function and encounter the statement ``return 1``,
 578you might wonder whether the ``1`` represents a Boolean truth value, an index,
 579or a coefficient that multiplies some other quantity.  If the statement is
 580``return True``, however, the meaning of the return value is quite clear.
 581
 582Python's Booleans were *not* added for the sake of strict type-checking.  A very
 583strict language such as Pascal would also prevent you performing arithmetic with
 584Booleans, and would require that the expression in an :keyword:`if` statement
 585always evaluate to a Boolean result.  Python is not this strict and never will
 586be, as :pep:`285` explicitly says.  This means you can still use any expression
 587in an :keyword:`if` statement, even ones that evaluate to a list or tuple or
 588some random object.  The Boolean type is a subclass of the :class:`int` class so
 589that arithmetic using a Boolean still works. ::
 590
 591   >>> True + 1
 592   2
 593   >>> False + 1
 594   1
 595   >>> False * 75
 596   0
 597   >>> True * 75
 598   75
 599
 600To sum up :const:`True` and :const:`False` in a sentence: they're alternative
 601ways to spell the integer values 1 and 0, with the single difference that
 602:func:`str` and :func:`repr` return the strings ``'True'`` and ``'False'``
 603instead of ``'1'`` and ``'0'``.
 604
 605
 606.. seealso::
 607
 608   :pep:`285` - Adding a bool type
 609      Written and implemented by GvR.
 610
 611.. ======================================================================
 612
 613
 614PEP 293: Codec Error Handling Callbacks
 615=======================================
 616
 617When encoding a Unicode string into a byte string, unencodable characters may be
 618encountered.  So far, Python has allowed specifying the error processing as
 619either "strict" (raising :exc:`UnicodeError`), "ignore" (skipping the
 620character), or "replace" (using a question mark in the output string), with
 621"strict" being the default behavior. It may be desirable to specify alternative
 622processing of such errors, such as inserting an XML character reference or HTML
 623entity reference into the converted string.
 624
 625Python now has a flexible framework to add different processing strategies.  New
 626error handlers can be added with :func:`codecs.register_error`, and codecs then
 627can access the error handler with :func:`codecs.lookup_error`. An equivalent C
 628API has been added for codecs written in C. The error handler gets the necessary
 629state information such as the string being converted, the position in the string
 630where the error was detected, and the target encoding.  The handler can then
 631either raise an exception or return a replacement string.
 632
 633Two additional error handlers have been implemented using this framework:
 634"backslashreplace" uses Python backslash quoting to represent unencodable
 635characters and "xmlcharrefreplace" emits XML character references.
 636
 637
 638.. seealso::
 639
 640   :pep:`293` - Codec Error Handling Callbacks
 641      Written and implemented by Walter Dörwald.
 642
 643.. ======================================================================
 644
 645
 646.. _section-pep301:
 647
 648PEP 301: Package Index and Metadata for Distutils
 649=================================================
 650
 651Support for the long-requested Python catalog makes its first appearance in 2.3.
 652
 653The heart of the catalog is the new Distutils :command:`register` command.
 654Running ``python setup.py register`` will collect the metadata describing a
 655package, such as its name, version, maintainer, description, &c., and send it to
 656a central catalog server.  The resulting catalog is available from
 657http://www.python.org/pypi.
 658
 659To make the catalog a bit more useful, a new optional *classifiers* keyword
 660argument has been added to the Distutils :func:`setup` function.  A list of
 661`Trove <http://catb.org/~esr/trove/>`_-style strings can be supplied to help
 662classify the software.
 663
 664Here's an example :file:`setup.py` with classifiers, written to be compatible
 665with older versions of the Distutils::
 666
 667   from distutils import core
 668   kw = {'name': "Quixote",
 669         'version': "0.5.1",
 670         'description': "A highly Pythonic Web application framework",
 671         # ...
 672         }
 673
 674   if (hasattr(core, 'setup_keywords') and
 675       'classifiers' in core.setup_keywords):
 676       kw['classifiers'] = \
 677           ['Topic :: Internet :: WWW/HTTP :: Dynamic Content',
 678            'Environment :: No Input/Output (Daemon)',
 679            'Intended Audience :: Developers'],
 680
 681   core.setup(**kw)
 682
 683The full list of classifiers can be obtained by running  ``python setup.py
 684register --list-classifiers``.
 685
 686
 687.. seealso::
 688
 689   :pep:`301` - Package Index and Metadata for Distutils
 690      Written and implemented by Richard Jones.
 691
 692.. ======================================================================
 693
 694
 695.. _section-pep302:
 696
 697PEP 302: New Import Hooks
 698=========================
 699
 700While it's been possible to write custom import hooks ever since the
 701:mod:`ihooks` module was introduced in Python 1.3, no one has ever been really
 702happy with it because writing new import hooks is difficult and messy.  There
 703have been various proposed alternatives such as the :mod:`imputil` and :mod:`iu`
 704modules, but none of them has ever gained much acceptance, and none of them were
 705easily usable from C code.
 706
 707:pep:`302` borrows ideas from its predecessors, especially from Gordon
 708McMillan's :mod:`iu` module.  Three new items  are added to the :mod:`sys`
 709module:
 710
 711* ``sys.path_hooks`` is a list of callable objects; most  often they'll be
 712  classes.  Each callable takes a string containing a path and either returns an
 713  importer object that will handle imports from this path or raises an
 714  :exc:`ImportError` exception if it can't handle this path.
 715
 716* ``sys.path_importer_cache`` caches importer objects for each path, so
 717  ``sys.path_hooks`` will only need to be traversed once for each path.
 718
 719* ``sys.meta_path`` is a list of importer objects that will be traversed before
 720  ``sys.path`` is checked.  This list is initially empty, but user code can add
 721  objects to it.  Additional built-in and frozen modules can be imported by an
 722  object added to this list.
 723
 724Importer objects must have a single method, :meth:`find_module(fullname,
 725path=None)`.  *fullname* will be a module or package name, e.g. ``string`` or
 726``distutils.core``.  :meth:`find_module` must return a loader object that has a
 727single method, :meth:`load_module(fullname)`, that creates and returns the
 728corresponding module object.
 729
 730Pseudo-code for Python's new import logic, therefore, looks something like this
 731(simplified a bit; see :pep:`302` for the full details)::
 732
 733   for mp in sys.meta_path:
 734       loader = mp(fullname)
 735       if loader is not None:
 736           <module> = loader.load_module(fullname)
 737
 738   for path in sys.path:
 739       for hook in sys.path_hooks:
 740           try:
 741               importer = hook(path)
 742           except ImportError:
 743               # ImportError, so try the other path hooks
 744               pass
 745           else:
 746               loader = importer.find_module(fullname)
 747               <module> = loader.load_module(fullname)
 748
 749   # Not found!
 750   raise ImportError
 751
 752
 753.. seealso::
 754
 755   :pep:`302` - New Import Hooks
 756      Written by Just van Rossum and Paul Moore. Implemented by Just van Rossum.
 757
 758.. ======================================================================
 759
 760
 761.. _section-pep305:
 762
 763PEP 305: Comma-separated Files
 764==============================
 765
 766Comma-separated files are a format frequently used for exporting data from
 767databases and spreadsheets.  Python 2.3 adds a parser for comma-separated files.
 768
 769Comma-separated format is deceptively simple at first glance::
 770
 771   Costs,150,200,3.95
 772
 773Read a line and call ``line.split(',')``: what could be simpler? But toss in
 774string data that can contain commas, and things get more complicated::
 775
 776   "Costs",150,200,3.95,"Includes taxes, shipping, and sundry items"
 777
 778A big ugly regular expression can parse this, but using the new  :mod:`csv`
 779package is much simpler::
 780
 781   import csv
 782
 783   input = open('datafile', 'rb')
 784   reader = csv.reader(input)
 785   for line in reader:
 786       print line
 787
 788The :func:`reader` function takes a number of different options. The field
 789separator isn't limited to the comma and can be changed to any character, and so
 790can the quoting and line-ending characters.
 791
 792Different dialects of comma-separated files can be defined and registered;
 793currently there are two dialects, both used by Microsoft Excel. A separate
 794:class:`csv.writer` class will generate comma-separated files from a succession
 795of tuples or lists, quoting strings that contain the delimiter.
 796
 797
 798.. seealso::
 799
 800   :pep:`305` - CSV File API
 801      Written and implemented  by Kevin Altis, Dave Cole, Andrew McNamara, Skip
 802      Montanaro, Cliff Wells.
 803
 804.. ======================================================================
 805
 806
 807.. _section-pep307:
 808
 809PEP 307: Pickle Enhancements
 810============================
 811
 812The :mod:`pickle` and :mod:`cPickle` modules received some attention during the
 8132.3 development cycle.  In 2.2, new-style classes could be pickled without
 814difficulty, but they weren't pickled very compactly; :pep:`307` quotes a trivial
 815example where a new-style class results in a pickled string three times longer
 816than that for a classic class.
 817
 818The solution was to invent a new pickle protocol.  The :func:`pickle.dumps`
 819function has supported a text-or-binary flag  for a long time.  In 2.3, this
 820flag is redefined from a Boolean to an integer: 0 is the old text-mode pickle
 821format, 1 is the old binary format, and now 2 is a new 2.3-specific format.  A
 822new constant, :const:`pickle.HIGHEST_PROTOCOL`, can be used to select the
 823fanciest protocol available.
 824
 825Unpickling is no longer considered a safe operation.  2.2's :mod:`pickle`
 826provided hooks for trying to prevent unsafe classes from being unpickled
 827(specifically, a :attr:`__safe_for_unpickling__` attribute), but none of this
 828code was ever audited and therefore it's all been ripped out in 2.3.  You should
 829not unpickle untrusted data in any version of Python.
 830
 831To reduce the pickling overhead for new-style classes, a new interface for
 832customizing pickling was added using three special methods:
 833:meth:`__getstate__`, :meth:`__setstate__`, and :meth:`__getnewargs__`.  Consult
 834:pep:`307` for the full semantics  of these methods.
 835
 836As a way to compress pickles yet further, it's now possible to use integer codes
 837instead of long strings to identify pickled classes. The Python Software
 838Foundation will maintain a list of standardized codes; there's also a range of
 839codes for private use.  Currently no codes have been specified.
 840
 841
 842.. seealso::
 843
 844   :pep:`307` - Extensions to the pickle protocol
 845      Written and implemented  by Guido van Rossum and Tim Peters.
 846
 847.. ======================================================================
 848
 849
 850.. _section-slices:
 851
 852Extended Slices
 853===============
 854
 855Ever since Python 1.4, the slicing syntax has supported an optional third "step"
 856or "stride" argument.  For example, these are all legal Python syntax:
 857``L[1:10:2]``, ``L[:-1:1]``, ``L[::-1]``.  This was added to Python at the
 858request of the developers of Numerical Python, which uses the third argument
 859extensively.  However, Python's built-in list, tuple, and string sequence types
 860have never supported this feature, raising a :exc:`TypeError` if you tried it.
 861Michael Hudson contributed a patch to fix this shortcoming.
 862
 863For example, you can now easily extract the elements of a list that have even
 864indexes::
 865
 866   >>> L = range(10)
 867   >>> L[::2]
 868   [0, 2, 4, 6, 8]
 869
 870Negative values also work to make a copy of the same list in reverse order::
 871
 872   >>> L[::-1]
 873   [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
 874
 875This also works for tuples, arrays, and strings::
 876
 877   >>> s='abcd'
 878   >>> s[::2]
 879   'ac'
 880   >>> s[::-1]
 881   'dcba'
 882
 883If you have a mutable sequence such as a list or an array you can assign to or
 884delete an extended slice, but there are some differences between assignment to
 885extended and regular slices.  Assignment to a regular slice can be used to
 886change the length of the sequence::
 887
 888   >>> a = range(3)
 889   >>> a
 890   [0, 1, 2]
 891   >>> a[1:3] = [4, 5, 6]
 892   >>> a
 893   [0, 4, 5, 6]
 894
 895Extended slices aren't this flexible.  When assigning to an extended slice, the
 896list on the right hand side of the statement must contain the same number of
 897items as the slice it is replacing::
 898
 899   >>> a = range(4)
 900   >>> a
 901   [0, 1, 2, 3]
 902   >>> a[::2]
 903   [0, 2]
 904   >>> a[::2] = [0, -1]
 905   >>> a
 906   [0, 1, -1, 3]
 907   >>> a[::2] = [0,1,2]
 908   Traceback (most recent call last):
 909     File "<stdin>", line 1, in ?
 910   ValueError: attempt to assign sequence of size 3 to extended slice of size 2
 911
 912Deletion is more straightforward::
 913
 914   >>> a = range(4)
 915   >>> a
 916   [0, 1, 2, 3]
 917   >>> a[::2]
 918   [0, 2]
 919   >>> del a[::2]
 920   >>> a
 921   [1, 3]
 922
 923One can also now pass slice objects to the :meth:`__getitem__` methods of the
 924built-in sequences::
 925
 926   >>> range(10).__getitem__(slice(0, 5, 2))
 927   [0, 2, 4]
 928
 929Or use slice objects directly in subscripts::
 930
 931   >>> range(10)[slice(0, 5, 2)]
 932   [0, 2, 4]
 933
 934To simplify implementing sequences that support extended slicing, slice objects
 935now have a method :meth:`indices(length)` which, given the length of a sequence,
 936returns a ``(start, stop, step)`` tuple that can be passed directly to
 937:func:`range`. :meth:`indices` handles omitted and out-of-bounds indices in a
 938manner consistent with regular slices (and this innocuous phrase hides a welter
 939of confusing details!).  The method is intended to be used like this::
 940
 941   class FakeSeq:
 942       ...
 943       def calc_item(self, i):
 944           ...
 945       def __getitem__(self, item):
 946           if isinstance(item, slice):
 947               indices = item.indices(len(self))
 948               return FakeSeq([self.calc_item(i) for i in range(*indices)])
 949           else:
 950               return self.calc_item(i)
 951
 952From this example you can also see that the built-in :class:`slice` object is
 953now the type object for the slice type, and is no longer a function.  This is
 954consistent with Python 2.2, where :class:`int`, :class:`str`, etc., underwent
 955the same change.
 956
 957.. ======================================================================
 958
 959
 960Other Language Changes
 961======================
 962
 963Here are all of the changes that Python 2.3 makes to the core Python language.
 964
 965* The :keyword:`yield` statement is now always a keyword, as described in
 966  section :ref:`section-generators` of this document.
 967
 968* A new built-in function :func:`enumerate` was added, as described in section
 969  :ref:`section-enumerate` of this document.
 970
 971* Two new constants, :const:`True` and :const:`False` were added along with the
 972  built-in :class:`bool` type, as described in section :ref:`section-bool` of this
 973  document.
 974
 975* The :func:`int` type constructor will now return a long integer instead of
 976  raising an :exc:`OverflowError` when a string or floating-point number is too
 977  large to fit into an integer.  This can lead to the paradoxical result that
 978  ``isinstance(int(expression), int)`` is false, but that seems unlikely to cause
 979  problems in practice.
 980
 981* Built-in types now support the extended slicing syntax, as described in
 982  section :ref:`section-slices` of this document.
 983
 984* A new built-in function, :func:`sum(iterable, start=0)`,  adds up the numeric
 985  items in the iterable object and returns their sum.  :func:`sum` only accepts
 986  numbers, meaning that you can't use it to concatenate a bunch of strings.
 987  (Contributed by Alex Martelli.)
 988
 989* ``list.insert(pos, value)`` used to  insert *value* at the front of the list
 990  when *pos* was negative.  The behaviour has now been changed to be consistent
 991  with slice indexing, so when *pos* is -1 the value will be inserted before the
 992  last element, and so forth.
 993
 994* ``list.index(value)``, which searches for *value*  within the list and returns
 995  its index, now takes optional  *start* and *stop* arguments to limit the search
 996  to  only part of the list.
 997
 998* Dictionaries have a new method, :meth:`pop(key[, *default*])`, that returns
 999  the value corresponding to *key* and removes that key/value pair from the
1000  dictionary.  If the requested key isn't present in the dictionary, *default* is
1001  returned if it's specified and :exc:`KeyError` raised if it isn't. ::
1002
1003     >>> d = {1:2}
1004     >>> d
1005     {1: 2}
1006     >>> d.pop(4)
1007     Traceback (most recent call last):
1008       File "stdin", line 1, in ?
1009     KeyError: 4
1010     >>> d.pop(1)
1011     2
1012     >>> d.pop(1)
1013     Traceback (most recent call last):
1014       File "stdin", line 1, in ?
1015     KeyError: 'pop(): dictionary is empty'
1016     >>> d
1017     {}
1018     >>>
1019
1020  There's also a new class method,  :meth:`dict.fromkeys(iterable, value)`, that
1021  creates a dictionary with keys taken from the supplied iterator *iterable* and
1022  all values set to *value*, defaulting to ``None``.
1023
1024  (Patches contributed by Raymond Hettinger.)
1025
1026  Also, the :func:`dict` constructor now accepts keyword arguments to simplify
1027  creating small dictionaries::
1028
1029     >>> dict(red=1, blue=2, green=3, black=4)
1030     {'blue': 2, 'black': 4, 'green': 3, 'red': 1}
1031
1032  (Contributed by Just van Rossum.)
1033
1034* The :keyword:`assert` statement no longer checks the ``__debug__`` flag, so
1035  you can no longer disable assertions by assigning to ``__debug__``. Running
1036  Python with the :option:`-O` switch will still generate code that doesn't
1037  execute any assertions.
1038
1039* Most type objects are now callable, so you can use them to create new objects
1040  such as functions, classes, and modules.  (This means that the :mod:`new` module
1041  can be deprecated in a future Python version, because you can now use the type
1042  objects available in the :mod:`types` module.) For example, you can create a new
1043  module object with the following code:
1044
1045  ::
1046
1047     >>> import types
1048     >>> m = types.ModuleType('abc','docstring')
1049     >>> m
1050     <module 'abc' (built-in)>
1051     >>> m.__doc__
1052     'docstring'
1053
1054* A new warning, :exc:`PendingDeprecationWarning` was added to indicate features
1055  which are in the process of being deprecated.  The warning will *not* be printed
1056  by default.  To check for use of features that will be deprecated in the future,
1057  supply :option:`-Walways::PendingDeprecationWarning::` on the command line or
1058  use :func:`warnings.filterwarnings`.
1059
1060* The process of deprecating string-based exceptions, as in ``raise "Error
1061  occurred"``, has begun.  Raising a string will now trigger
1062  :exc:`PendingDeprecationWarning`.
1063
1064* Using ``None`` as a variable name will now result in a :exc:`SyntaxWarning`
1065  warning.  In a future version of Python, ``None`` may finally become a keyword.
1066
1067* The :meth:`xreadlines` method of file objects, introduced in Python 2.1, is no
1068  longer necessary because files now behave as their own iterator.
1069  :meth:`xreadlines` was originally introduced as a faster way to loop over all
1070  the lines in a file, but now you can simply write ``for line in file_obj``.
1071  File objects also have a new read-only :attr:`encoding` attribute that gives the
1072  encoding used by the file; Unicode strings written to the file will be
1073  automatically  converted to bytes using the given encoding.
1074
1075* The method resolution order used by new-style classes has changed, though
1076  you'll only notice the difference if you have a really complicated inheritance
1077  hierarchy.  Classic classes are unaffected by this change.  Python 2.2
1078  originally used a topological sort of a class's ancestors, but 2.3 now uses the
1079  C3 algorithm as described in the paper `"A Monotonic Superclass Linearization
1080  for Dylan" <http://www.webcom.com/haahr/dylan/linearization-oopsla96.html>`_. To
1081  understand the motivation for this change,  read Michele Simionato's article
1082  `"Python 2.3 Method Resolution Order" <http://www.python.org/2.3/mro.html>`_, or
1083  read the thread on python-dev starting with the message at
1084  http://mail.python.org/pipermail/python-dev/2002-October/029035.html. Samuele
1085  Pedroni first pointed out the problem and also implemented the fix by coding the
1086  C3 algorithm.
1087
1088* Python runs multithreaded programs by switching between threads after
1089  executing N bytecodes.  The default value for N has been increased from 10 to
1090  100 bytecodes, speeding up single-threaded applications by reducing the
1091  switching overhead.  Some multithreaded applications may suffer slower response
1092  time, but that's easily fixed by setting the limit back to a lower number using
1093  :func:`sys.setcheckinterval(N)`. The limit can be retrieved with the new
1094  :func:`sys.getcheckinterval` function.
1095
1096* One minor but far-reaching change is that the names of extension types defined
1097  by the modules included with Python now contain the module and a ``'.'`` in
1098  front of the type name.  For example, in Python 2.2, if you created a socket and
1099  printed its :attr:`__class__`, you'd get this output::
1100
1101     >>> s = socket.socket()
1102     >>> s.__class__
1103     <type 'socket'>
1104
1105  In 2.3, you get this::
1106
1107     >>> s.__class__
1108     <type '_socket.socket'>
1109
1110* One of the noted incompatibilities between old- and new-style classes has been
1111  removed: you can now assign to the :attr:`__name__` and :attr:`__bases__`
1112  attributes of new-style classes.  There are some restrictions on what can be
1113  assigned to :attr:`__bases__` along the lines of those relating to assigning to
1114  an instance's :attr:`__class__` attribute.
1115
1116.. ======================================================================
1117
1118
1119String Changes
1120--------------
1121
1122* The :keyword:`in` operator now works differently for strings. Previously, when
1123  evaluating ``X in Y`` where *X* and *Y* are strings, *X* could only be a single
1124  character. That's now changed; *X* can be a string of any length, and ``X in Y``
1125  will return :const:`True` if *X* is a substring of *Y*.  If *X* is the empty
1126  string, the result is always :const:`True`. ::
1127
1128     >>> 'ab' in 'abcd'
1129     True
1130     >>> 'ad' in 'abcd'
1131     False
1132     >>> '' in 'abcd'
1133     True
1134
1135  Note that this doesn't tell you where the substring starts; if you need that
1136  information, use the :meth:`find` string method.
1137
1138* The :meth:`strip`, :meth:`lstrip`, and :meth:`rstrip` string methods now have
1139  an optional argument for specifying the characters to strip.  The default is
1140  still to remove all whitespace characters::
1141
1142     >>> '   abc '.strip()
1143     'abc'
1144     >>> '><><abc<><><>'.strip('<>')
1145     'abc'
1146     >>> '><><abc<><><>\n'.strip('<>')
1147     'abc<><><>\n'
1148     >>> u'\u4000\u4001abc\u4000'.strip(u'\u4000')
1149     u'\u4001abc'
1150     >>>
1151
1152  (Suggested by Simon Brunning and implemented by Walter Dörwald.)
1153
1154* The :meth:`startswith` and :meth:`endswith` string methods now accept negative
1155  numbers for the *start* and *end* parameters.
1156
1157* Another new string method is :meth:`zfill`, originally a function in the
1158  :mod:`string` module.  :meth:`zfill` pads a numeric string with zeros on the
1159  left until it's the specified width. Note that the ``%`` operator is still more
1160  flexible and powerful than :meth:`zfill`. ::
1161
1162     >>> '45'.zfill(4)
1163     '0045'
1164     >>> '12345'.zfill(4)
1165     '12345'
1166     >>> 'goofy'.zfill(6)
1167     '0goofy'
1168
1169  (Contributed by Walter Dörwald.)
1170
1171* A new type object, :class:`basestring`, has been added. Both 8-bit strings and
1172  Unicode strings inherit from this type, so ``isinstance(obj, basestring)`` will
1173  return :const:`True` for either kind of string.  It's a completely abstract
1174  type, so you can't create :class:`basestring` instances.
1175
1176* Interned strings are no longer immortal and will now be garbage-collected in
1177  the usual way when the only reference to them is from the internal dictionary of
1178  interned strings.  (Implemented by Oren Tirosh.)
1179
1180.. ======================================================================
1181
1182
1183Optimizations
1184-------------
1185
1186* The creation of new-style class instances has been made much faster; they're
1187  now faster than classic classes!
1188
1189* The :meth:`sort` method of list objects has been extensively rewritten by Tim
1190  Peters, and the implementation is significantly faster.
1191
1192* Multiplication of large long integers is now much faster thanks to an
1193  implementation of Karatsuba multiplication, an algorithm that scales better than
1194  the O(n\*n) required for the grade-school multiplication algorithm.  (Original
1195  patch by Christopher A. Craig, and significantly reworked by Tim Peters.)
1196
1197* The ``SET_LINENO`` opcode is now gone.  This may provide a small speed
1198  increase, depending on your compiler's idiosyncrasies. See section
1199  :ref:`section-other` for a longer explanation. (Removed by Michael Hudson.)
1200
1201* :func:`xrange` objects now have their own iterator, making ``for i in
1202  xrange(n)`` slightly faster than ``for i in range(n)``.  (Patch by Raymond
1203  Hettinger.)
1204
1205* A number of small rearrangements have been made in various hotspots to improve
1206  performance, such as inlining a function or removing some code.  (Implemented
1207  mostly by GvR, but lots of people have contributed single changes.)
1208
1209The net result of the 2.3 optimizations is that Python 2.3 runs the  pystone
1210benchmark around 25% faster than Python 2.2.
1211
1212.. ======================================================================
1213
1214
1215New, Improved, and Deprecated Modules
1216=====================================
1217
1218As usual, Python's standard library received a number of enhancements and bug
1219fixes.  Here's a partial list of the most notable changes, sorted alphabetically
1220by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more
1221complete list of changes, or look through the CVS logs for all the details.
1222
1223* The :mod:`array` module now supports arrays of Unicode characters using the
1224  ``'u'`` format character.  Arrays also now support using the ``+=`` assignment
1225  operator to add another array's contents, and the ``*=`` assignment operator to
1226  repeat an array. (Contributed by Jason Orendorff.)
1227
1228* The :mod:`bsddb` module has been replaced by version 4.1.6 of the `PyBSDDB
1229  <http://pybsddb.sourceforge.net>`_ package, providing a more complete interface
1230  to the transactional features of the BerkeleyDB library.
1231
1232  The old version of the module has been renamed to  :mod:`bsddb185` and is no
1233  longer built automatically; you'll  have to edit :file:`Modules/Setup` to enable
1234  it.  Note that the new :mod:`bsddb` package is intended to be compatible with
1235  the  old module, so be sure to file bugs if you discover any incompatibilities.
1236  When upgrading to Python 2.3, if the new interpreter is compiled with a new
1237  version of  the underlying BerkeleyDB library, you will almost certainly have to
1238  convert your database files to the new version.  You can do this fairly easily
1239  with the new scripts :file:`db2pickle.py` and :file:`pickle2db.py` which you
1240  will find in the distribution's :file:`Tools/scripts` directory.  If you've
1241  already been using the PyBSDDB package and importing it as :mod:`bsddb3`, you
1242  will have to change your ``import`` statements to import it as :mod:`bsddb`.
1243
1244* The new :mod:`bz2` module is an interface to the bz2 data compression library.
1245  bz2-compressed data is usually smaller than  corresponding :mod:`zlib`\
1246  -compressed data. …

Large files files are truncated, but you can click here to view the full file