f | **************************** |
n | What's New in Python 2.3 |
n | What's New in Python 2.3 |
| **************************** |
| |
| :Author: A.M. Kuchling |
| |
| .. |release| replace:: 1.01 |
| |
n | .. % $Id: whatsnew23.tex 50964 2006-07-30 03:03:43Z fred.drake $ |
n | .. $Id: whatsnew23.tex 54631 2007-03-31 11:58:36Z georg.brandl $ |
| |
| This article explains the new features in Python 2.3. Python 2.3 was released |
| on July 29, 2003. |
| |
| The main themes for Python 2.3 are polishing some of the features added in 2.2, |
| adding various small but useful enhancements to the core language, and expanding |
| the standard library. The new object model introduced in the previous version |
| has benefited from 18 months of bugfixes and from optimization efforts that have |
| support for the long-awaited Python catalog, an updated version of IDLE, and |
| modules for logging messages, wrapping text, parsing CSV files, processing |
| command-line options, using BerkeleyDB databases... the list of new and |
| enhanced modules is lengthy. |
| |
| This article doesn't attempt to provide a complete specification of the new |
| features, but instead provides a convenient overview. For full details, you |
| should refer to the documentation for Python 2.3, such as the Python Library |
n | Reference (XXX reference: ../lib/lib.html) and the Python Reference Manual (XXX |
n | Reference and the Python Reference Manual. If you want to understand the |
| reference: ../ref/ref.html). If you want to understand the complete |
| implementation and design rationale, refer to the PEP for a particular new |
| complete implementation and design rationale, refer to the PEP for a particular |
| feature. |
| new feature. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| PEP 218: A Standard Set Datatype |
| ================================ |
| |
| The new :mod:`sets` module contains an implementation of a set datatype. The |
| :class:`Set` class is for mutable sets, sets that can have members added and |
| removed. The :class:`ImmutableSet` class is for sets that can't be modified, |
| |
| |
| .. seealso:: |
| |
| :pep:`218` - Adding a Built-In Set Object Type |
| PEP written by Greg V. Wilson. Implemented by Greg V. Wilson, Alex Martelli, and |
| GvR. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| .. _section-generators: |
| |
| PEP 255: Simple Generators |
| ========================== |
| |
| In Python 2.2, generators were added as an optional feature, to be enabled by a |
| yield x |
| |
| Two other examples in :file:`Lib/test/test_generators.py` produce solutions for |
| the N-Queens problem (placing $N$ queens on an $NxN$ chess board so that no |
| queen threatens another) and the Knight's Tour (a route that takes a knight to |
| every square of an $NxN$ chessboard without visiting any square twice). |
| |
| The idea of generators comes from other programming languages, especially Icon |
n | (`<http://www.cs.arizona.edu/icon/>`_), where the idea of generators is central. |
n | (http://www.cs.arizona.edu/icon/), where the idea of generators is central. In |
| In Icon, every expression and function call behaves like a generator. One |
| Icon, every expression and function call behaves like a generator. One example |
| example from "An Overview of the Icon Programming Language" at |
| from "An Overview of the Icon Programming Language" at |
| `<http://www.cs.arizona.edu/icon/docs/ipd266.htm>`_ gives an idea of what this |
| http://www.cs.arizona.edu/icon/docs/ipd266.htm gives an idea of what this looks |
| looks like:: |
| like:: |
| |
| sentence := "Store it in the neighboring harbor" |
| if (i := find("or", sentence)) > 5 then write(i) |
| |
| In Icon the :func:`find` function returns the indexes at which the substring |
| "or" is found: 3, 23, 33. In the :keyword:`if` statement, ``i`` is first |
| assigned a value of 3, but 3 is less than 5, so the comparison fails, and Icon |
| retries it with the second value of 23. 23 is greater than 5, so the comparison |
| |
| |
| .. seealso:: |
| |
| :pep:`255` - Simple Generators |
| Written by Neil Schemenauer, Tim Peters, Magnus Lie Hetland. Implemented mostly |
| by Neil Schemenauer and Tim Peters, with other fixes from the Python Labs crew. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| .. _section-encodings: |
| |
| PEP 263: Source Code Encodings |
| ============================== |
| |
| Python source files can now be declared as being in different character set |
| |
| |
| .. seealso:: |
| |
| :pep:`263` - Defining Python Source Code Encodings |
| Written by Marc-André Lemburg and Martin von Löwis; implemented by Suzuki Hisao |
| and Martin von Löwis. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| PEP 273: Importing Modules from ZIP Archives |
| ============================================ |
| |
| The new :mod:`zipimport` module adds support for importing modules from a ZIP- |
| format archive. You don't need to import the module explicitly; it will be |
| automatically imported if a ZIP archive's filename is added to ``sys.path``. |
| amk@nyman:~/src/python$ unzip -l /tmp/example.zip |
| Archive: /tmp/example.zip |
| Length Date Time Name |
| -------- ---- ---- ---- |
| 8467 11-26-02 22:30 jwzthreading.py |
| -------- ------- |
| 8467 1 file |
| amk@nyman:~/src/python$ ./python |
n | Python 2.3 (#1, Aug 1 2003, 19:54:32) |
n | Python 2.3 (#1, Aug 1 2003, 19:54:32) |
| >>> import sys |
| >>> sys.path.insert(0, '/tmp/example.zip') # Add .zip file to front of path |
| >>> import jwzthreading |
| >>> jwzthreading.__file__ |
| '/tmp/example.zip/jwzthreading.py' |
| >>> |
| |
| An entry in ``sys.path`` can now be the filename of a ZIP archive. The ZIP |
| .. seealso:: |
| |
| :pep:`273` - Import Modules from Zip Archives |
| Written by James C. Ahlstrom, who also provided an implementation. Python 2.3 |
| follows the specification in :pep:`273`, but uses an implementation written by |
| Just van Rossum that uses the import hooks described in :pep:`302`. See section |
| :ref:`section-pep302` for a description of the new import hooks. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| PEP 277: Unicode file name support for Windows NT |
| ================================================= |
| |
| On Windows NT, 2000, and XP, the system stores file names as Unicode strings. |
| Traditionally, Python has represented file names as byte strings, which is |
| inadequate because it renders some file names inaccessible. |
| |
| |
| .. seealso:: |
| |
| :pep:`277` - Unicode file name support for Windows NT |
| Written by Neil Hodgson; implemented by Neil Hodgson, Martin von Löwis, and Mark |
| Hammond. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| PEP 278: Universal Newline Support |
| ================================== |
| |
| The three major operating systems used today are Microsoft Windows, Apple's |
| Macintosh OS, and the various Unix derivatives. A minor irritation of cross- |
| platform work is that these three platforms all use different characters to |
| L[i] = result |
| |
| |
| .. seealso:: |
| |
| :pep:`279` - The enumerate() built-in function |
| Written and implemented by Raymond D. Hettinger. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| PEP 282: The logging Package |
| ============================ |
| |
| A standard package for writing logs, :mod:`logging`, has been added to Python |
| 2.3. It provides a powerful and flexible mechanism for generating logging |
| output which can then be filtered and processed in various ways. A |
| can modify the record before passing it along. When they're finally output, |
| :class:`LogRecord` instances are converted to text by a :class:`Formatter` |
| class. All of these classes can be replaced by your own specially-written |
| classes. |
| |
| With all of these features the :mod:`logging` package should provide enough |
| flexibility for even the most complicated applications. This is only an |
| incomplete overview of its features, so please see the package's reference |
n | documentation (XXX reference: ../lib/module-logging.html) for all of the |
| details. Reading :pep:`282` will also be helpful. |
| documentation for all of the details. Reading :pep:`282` will also be helpful. |
| |
| |
| .. seealso:: |
| |
| :pep:`282` - A Logging System |
| Written by Vinay Sajip and Trent Mick; implemented by Vinay Sajip. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| .. _section-bool: |
| |
| PEP 285: A Boolean Type |
| ======================= |
| |
| A Boolean type was added to Python 2.3. Two new constants were added to the |
| instead of ``'1'`` and ``'0'``. |
| |
| |
| .. seealso:: |
| |
| :pep:`285` - Adding a bool type |
| Written and implemented by GvR. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| PEP 293: Codec Error Handling Callbacks |
| ======================================= |
| |
| When encoding a Unicode string into a byte string, unencodable characters may be |
| encountered. So far, Python has allowed specifying the error processing as |
| either "strict" (raising :exc:`UnicodeError`), "ignore" (skipping the |
| characters and "xmlcharrefreplace" emits XML character references. |
| |
| |
| .. seealso:: |
| |
| :pep:`293` - Codec Error Handling Callbacks |
| Written and implemented by Walter Dörwald. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| .. _section-pep301: |
| |
| PEP 301: Package Index and Metadata for Distutils |
| ================================================= |
| |
| Support for the long-requested Python catalog makes its first appearance in 2.3. |
| |
| The heart of the catalog is the new Distutils :command:`register` command. |
| Running ``python setup.py register`` will collect the metadata describing a |
| package, such as its name, version, maintainer, description, &c., and send it to |
| a central catalog server. The resulting catalog is available from |
n | `<http://www.python.org/pypi>`_. |
n | http://www.python.org/pypi. |
| |
| To make the catalog a bit more useful, a new optional *classifiers* keyword |
| argument has been added to the Distutils :func:`setup` function. A list of |
| `Trove <http://catb.org/~esr/trove/>`_-style strings can be supplied to help |
| classify the software. |
| |
| Here's an example :file:`setup.py` with classifiers, written to be compatible |
| with older versions of the Distutils:: |
| |
| from distutils import core |
| kw = {'name': "Quixote", |
| 'version': "0.5.1", |
| 'description': "A highly Pythonic Web application framework", |
| # ... |
| } |
| |
n | if (hasattr(core, 'setup_keywords') and |
n | if (hasattr(core, 'setup_keywords') and |
| 'classifiers' in core.setup_keywords): |
| kw['classifiers'] = \ |
| ['Topic :: Internet :: WWW/HTTP :: Dynamic Content', |
| 'Environment :: No Input/Output (Daemon)', |
| 'Intended Audience :: Developers'], |
| |
| core.setup(**kw) |
| |
| |
| |
| .. seealso:: |
| |
| :pep:`305` - CSV File API |
| Written and implemented by Kevin Altis, Dave Cole, Andrew McNamara, Skip |
| Montanaro, Cliff Wells. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
n | .. _section-pep305: |
n | .. _section-pep307: |
| |
| PEP 307: Pickle Enhancements |
| ============================ |
| |
| The :mod:`pickle` and :mod:`cPickle` modules received some attention during the |
| 2.3 development cycle. In 2.2, new-style classes could be pickled without |
| difficulty, but they weren't pickled very compactly; :pep:`307` quotes a trivial |
| example where a new-style class results in a pickled string three times longer |
| else: |
| return self.calc_item(i) |
| |
| From this example you can also see that the built-in :class:`slice` object is |
| now the type object for the slice type, and is no longer a function. This is |
| consistent with Python 2.2, where :class:`int`, :class:`str`, etc., underwent |
| the same change. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| Other Language Changes |
| ====================== |
| |
| Here are all of the changes that Python 2.3 makes to the core Python language. |
| |
| * The :keyword:`yield` statement is now always a keyword, as described in |
| all values set to *value*, defaulting to ``None``. |
| |
| (Patches contributed by Raymond Hettinger.) |
| |
| Also, the :func:`dict` constructor now accepts keyword arguments to simplify |
| creating small dictionaries:: |
| |
| >>> dict(red=1, blue=2, green=3, black=4) |
n | {'blue': 2, 'black': 4, 'green': 3, 'red': 1} |
n | {'blue': 2, 'black': 4, 'green': 3, 'red': 1} |
| |
| (Contributed by Just van Rossum.) |
| |
| * The :keyword:`assert` statement no longer checks the ``__debug__`` flag, so |
| you can no longer disable assertions by assigning to ``__debug__``. Running |
| Python with the :option:`-O` switch will still generate code that doesn't |
| execute any assertions. |
| |
| * Most type objects are now callable, so you can use them to create new objects |
| such as functions, classes, and modules. (This means that the :mod:`new` module |
| can be deprecated in a future Python version, because you can now use the type |
| objects available in the :mod:`types` module.) For example, you can create a new |
| module object with the following code: |
n | |
| .. % XXX should new.py use PendingDeprecationWarning? |
| |
| :: |
| |
| >>> import types |
| >>> m = types.ModuleType('abc','docstring') |
| >>> m |
| <module 'abc' (built-in)> |
| >>> m.__doc__ |
| you'll only notice the difference if you have a really complicated inheritance |
| hierarchy. Classic classes are unaffected by this change. Python 2.2 |
| originally used a topological sort of a class's ancestors, but 2.3 now uses the |
| C3 algorithm as described in the paper `"A Monotonic Superclass Linearization |
| for Dylan" <http://www.webcom.com/haahr/dylan/linearization-oopsla96.html>`_. To |
| understand the motivation for this change, read Michele Simionato's article |
| `"Python 2.3 Method Resolution Order" <http://www.python.org/2.3/mro.html>`_, or |
| read the thread on python-dev starting with the message at |
n | `<http://mail.python.org/pipermail/python-dev/2002-October/029035.html>`_. |
n | http://mail.python.org/pipermail/python-dev/2002-October/029035.html. Samuele |
| Samuele Pedroni first pointed out the problem and also implemented the fix by |
| Pedroni first pointed out the problem and also implemented the fix by coding the |
| coding the C3 algorithm. |
| C3 algorithm. |
| |
| * Python runs multithreaded programs by switching between threads after |
| executing N bytecodes. The default value for N has been increased from 10 to |
| 100 bytecodes, speeding up single-threaded applications by reducing the |
| switching overhead. Some multithreaded applications may suffer slower response |
| time, but that's easily fixed by setting the limit back to a lower number using |
| :func:`sys.setcheckinterval(N)`. The limit can be retrieved with the new |
| :func:`sys.getcheckinterval` function. |
| <type '_socket.socket'> |
| |
| * One of the noted incompatibilities between old- and new-style classes has been |
| removed: you can now assign to the :attr:`__name__` and :attr:`__bases__` |
| attributes of new-style classes. There are some restrictions on what can be |
| assigned to :attr:`__bases__` along the lines of those relating to assigning to |
| an instance's :attr:`__class__` attribute. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| String Changes |
| -------------- |
| |
| * The :keyword:`in` operator now works differently for strings. Previously, when |
| evaluating ``X in Y`` where *X* and *Y* are strings, *X* could only be a single |
| character. That's now changed; *X* can be a string of any length, and ``X in Y`` |
| Unicode strings inherit from this type, so ``isinstance(obj, basestring)`` will |
| return :const:`True` for either kind of string. It's a completely abstract |
| type, so you can't create :class:`basestring` instances. |
| |
| * Interned strings are no longer immortal and will now be garbage-collected in |
| the usual way when the only reference to them is from the internal dictionary of |
| interned strings. (Implemented by Oren Tirosh.) |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| Optimizations |
| ------------- |
| |
| * The creation of new-style class instances has been made much faster; they're |
| now faster than classic classes! |
| |
| |
| * A number of small rearrangements have been made in various hotspots to improve |
| performance, such as inlining a function or removing some code. (Implemented |
| mostly by GvR, but lots of people have contributed single changes.) |
| |
| The net result of the 2.3 optimizations is that Python 2.3 runs the pystone |
| benchmark around 25% faster than Python 2.2. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| New, Improved, and Deprecated Modules |
| ===================================== |
| |
| As usual, Python's standard library received a number of enhancements and bug |
| fixes. Here's a partial list of the most notable changes, sorted alphabetically |
| by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more |
| |
| * The :mod:`gzip` module can now handle files exceeding 2 GiB. |
| |
| * The new :mod:`heapq` module contains an implementation of a heap queue |
| algorithm. A heap is an array-like data structure that keeps items in a |
| partially sorted order such that, for every index *k*, ``heap[k] <= |
| heap[2*k+1]`` and ``heap[k] <= heap[2*k+2]``. This makes it quick to remove the |
| smallest item, and inserting a new item while maintaining the heap property is |
n | O(lg n). (See `<http://www.nist.gov/dads/HTML/priorityque.html>`_ for more |
n | O(lg n). (See http://www.nist.gov/dads/HTML/priorityque.html for more |
| information about the priority queue data structure.) |
| |
| The :mod:`heapq` module provides :func:`heappush` and :func:`heappop` functions |
| for adding and removing items while maintaining the heap property on top of some |
| other mutable Python sequence type. Here's an example that uses a Python list:: |
| |
| >>> import heapq |
| >>> heap = [] |
| >>> heapq.heappop(heap) |
| 3 |
| >>> heap |
| [5, 7, 11] |
| |
| (Contributed by Kevin O'Connor.) |
| |
| * The IDLE integrated development environment has been updated using the code |
n | from the IDLEfork project (`<http://idlefork.sf.net>`_). The most notable |
n | from the IDLEfork project (http://idlefork.sf.net). The most notable feature is |
| feature is that the code being developed is now executed in a subprocess, |
| that the code being developed is now executed in a subprocess, meaning that |
| meaning that there's no longer any need for manual ``reload()`` operations. |
| there's no longer any need for manual ``reload()`` operations. IDLE's core code |
| IDLE's core code has been incorporated into the standard library as the |
| has been incorporated into the standard library as the :mod:`idlelib` package. |
| :mod:`idlelib` package. |
| |
| * The :mod:`imaplib` module now supports IMAP over SSL. (Contributed by Piers |
| Lauder and Tino Lange.) |
| |
| * The :mod:`itertools` contains a number of useful functions for use with |
| iterators, inspired by various functions provided by the ML and Haskell |
| languages. For example, ``itertools.ifilter(predicate, iterator)`` returns all |
| elements in the iterator for which the function :func:`predicate` returns |
| :const:`True`, and ``itertools.repeat(obj, N)`` returns ``obj`` *N* times. |
| There are a number of other functions in the module; see the package's reference |
n | documentation (XXX reference: ../lib/module-itertools.html) for details. |
n | documentation for details. |
| (Contributed by Raymond Hettinger.) |
| |
| * Two new functions in the :mod:`math` module, :func:`degrees(rads)` and |
| :func:`radians(degs)`, convert between radians and degrees. Other functions in |
| the :mod:`math` module such as :func:`math.sin` and :func:`math.cos` have always |
| required input values measured in radians. Also, an optional *base* argument |
| was added to :func:`math.log` to make it easier to compute logarithms for bases |
| other than ``e`` and ``10``. (Contributed by Raymond Hettinger.) |
| will be now; if it be not now, yet |
| it will come: the readiness is all. |
| >>> |
| |
| The module also contains a :class:`TextWrapper` class that actually implements |
| the text wrapping strategy. Both the :class:`TextWrapper` class and the |
| :func:`wrap` and :func:`fill` functions support a number of additional keyword |
| arguments for fine-tuning the formatting; consult the module's documentation |
n | (XXX reference: ../lib/module-textwrap.html) for details. (Contributed by Greg |
n | for details. (Contributed by Greg Ward.) |
| Ward.) |
| |
| * The :mod:`thread` and :mod:`threading` modules now have companion modules, |
| :mod:`dummy_thread` and :mod:`dummy_threading`, that provide a do-nothing |
| implementation of the :mod:`thread` module's interface for platforms where |
| threads are not supported. The intention is to simplify thread-aware modules |
| (ones that *don't* rely on threads to run) by putting the following code at the |
| top:: |
| |
| * The :mod:`Tkinter` module now works with a thread-enabled version of Tcl. |
| Tcl's threading model requires that widgets only be accessed from the thread in |
| which they're created; accesses from another thread can cause Tcl to panic. For |
| certain Tcl interfaces, :mod:`Tkinter` will now automatically avoid this when a |
| widget is accessed from a different thread by marshalling a command, passing it |
| to the correct thread, and waiting for the results. Other interfaces can't be |
| handled automatically but :mod:`Tkinter` will now raise an exception on such an |
| access so that you can at least find out about the problem. See |
n | `<http://mail.python.org/pipermail/python-dev/2002-December/031107.html>`_ for a |
n | http://mail.python.org/pipermail/python-dev/2002-December/031107.html for a more |
| more detailed explanation of this change. (Implemented by Martin von Löwis.) |
| detailed explanation of this change. (Implemented by Martin von Löwis.) |
| |
| .. % |
| |
| * Calling Tcl methods through :mod:`_tkinter` no longer returns only strings. |
| Instead, if Tcl returns other objects those objects are converted to their |
| Python equivalent, if one exists, or wrapped with a :class:`_tkinter.Tcl_Obj` |
| object if no Python equivalent exists. This behavior can be controlled through |
| the :meth:`wantobjects` method of :class:`tkapp` objects. |
| |
| When using :mod:`_tkinter` through the :mod:`Tkinter` module (as most Tkinter |
| ... try: |
| ... i = self.keylist.index(key) |
| ... except ValueError: |
| ... raise KeyError |
| ... self.keylist.pop(i) |
| ... self.valuelist.pop(i) |
| ... def keys(self): |
| ... return list(self.keylist) |
n | ... |
n | ... |
| >>> s = SeqDict() |
| >>> dir(s) # See that other dictionary methods are implemented |
| ['__cmp__', '__contains__', '__delitem__', '__doc__', '__getitem__', |
| '__init__', '__iter__', '__len__', '__module__', '__repr__', |
| '__setitem__', 'clear', 'get', 'has_key', 'items', 'iteritems', |
| 'iterkeys', 'itervalues', 'keylist', 'keys', 'pop', 'popitem', |
| 'setdefault', 'update', 'valuelist', 'values'] |
| |
| |
| * Support for internationalized domain names (RFCs 3454, 3490, 3491, and 3492) |
| has been added. The "idna" encoding can be used to convert between a Unicode |
| domain name and the ASCII-compatible encoding (ACE) of that name. :: |
| |
| >{}>{}> u"www.Alliancefrançaise.nu".encode("idna") |
| 'www.xn--alliancefranaise-npb.nu' |
| |
n | The :mod:`socket` module has also been extended to transparently convert Unicode |
n | The :mod:`socket` module has also been extended to transparently convert |
| hostnames to the ACE version before passing them to the C library. Modules that |
| Unicode hostnames to the ACE version before passing them to the C library. |
| deal with hostnames such as :mod:`httplib` and :mod:`ftplib`) also support |
| Modules that deal with hostnames such as :mod:`httplib` and :mod:`ftplib`) |
| Unicode host names; :mod:`httplib` also sends HTTP ``Host`` headers using the |
| also support Unicode host names; :mod:`httplib` also sends HTTP ``Host`` |
| ACE version of the domain name. :mod:`urllib` supports Unicode URLs with non- |
| headers using the ACE version of the domain name. :mod:`urllib` supports |
| ASCII host names as long as the ``path`` part of the URL is ASCII only. |
| Unicode URLs with non-ASCII host names as long as the ``path`` part of the URL |
| is ASCII only. |
| |
| To implement this change, the :mod:`stringprep` module, the ``mkstringprep`` |
| tool and the ``punycode`` encoding have been added. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| Date/Time Type |
| -------------- |
| |
| Date and time types suitable for expressing timestamps were added as the |
| :mod:`datetime` module. The types don't support different calendars or many |
| fancy features, and just stick to the basics of representing time. |
| |
| Instances can be compared, hashed, and converted to strings (the result is the |
| same as that of :meth:`isoformat`). :class:`date` and :class:`datetime` |
| instances can be subtracted from each other, and added to :class:`timedelta` |
| instances. The largest missing feature is that there's no standard library |
| support for parsing strings and getting back a :class:`date` or |
| :class:`datetime`. |
| |
n | For more information, refer to the module's reference documentation (XXX |
n | For more information, refer to the module's reference documentation. |
| reference: ../lib/module-datetime.html). (Contributed by Tim Peters.) |
| (Contributed by Tim Peters.) |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| The optparse Module |
| ------------------- |
| |
| The :mod:`getopt` module provides simple parsing of command-line arguments. The |
| new :mod:`optparse` module (originally named Optik) provides more elaborate |
| command-line parsing that follows the Unix conventions, automatically creates |
| usage: opt.py [options] |
| |
| options: |
| -h, --help show this help message and exit |
| -iINPUT, --input=INPUT |
| set input filename |
| -lLENGTH, --length=LENGTH |
| set maximum length of output |
n | $ |
n | $ |
| |
n | See the module's documentation (XXX reference: ../lib/module-optparse.html) for |
n | See the module's documentation for more details. |
| more details. |
| |
n | .. % $ prevent Emacs tex-mode from getting confused |
| |
| Optik was written by Greg Ward, with suggestions from the readers of the Getopt |
| SIG. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| .. _section-pymalloc: |
| |
| Pymalloc: A Specialized Object Allocator |
| ======================================== |
| |
| Pymalloc, a specialized object allocator written by Vladimir Marangozov, was a |
| |
| .. seealso:: |
| |
| http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Objects/obmalloc.c |
| For the full details of the pymalloc implementation, see the comments at the top |
| of the file :file:`Objects/obmalloc.c` in the Python source code. The above |
| link points to the file within the SourceForge CVS browser. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| Build and C API Changes |
| ======================= |
| |
| Changes to Python's build process and to the C API include: |
| |
| * The cycle detection implementation used by the garbage collection has proven |
| |
| * If you dynamically allocate type objects in your extension, you should be |
| aware of a change in the rules relating to the :attr:`__module__` and |
| :attr:`__name__` attributes. In summary, you will want to ensure the type's |
| dictionary contains a ``'__module__'`` key; making the module name the part of |
| the type name leading up to the final period will no longer have the desired |
| effect. For more detail, read the API reference documentation or the source. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| Port-Specific Changes |
| --------------------- |
| |
| Support for a port to IBM's OS/2 using the EMX runtime environment was merged |
| into the main Python source tree. EMX is a POSIX emulation layer over the OS/2 |
| system APIs. The Python port for EMX tries to support all the POSIX-like |
| compatibility. This means that modules will no longer fail to load if a single |
| routine is missing on the current OS version. Instead calling the missing |
| routine will raise an exception. (Contributed by Jack Jansen.) |
| |
| The RPM spec files, found in the :file:`Misc/RPM/` directory in the Python |
| source distribution, were updated for 2.3. (Contributed by Sean Reifschneider.) |
| |
| Other new platforms now supported by Python include AtheOS |
n | (`<http://www.atheos.cx/>`_), GNU/Hurd, and OpenVMS. |
n | (http://www.atheos.cx/), GNU/Hurd, and OpenVMS. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| .. _section-other: |
| |
| Other Changes and Fixes |
| ======================= |
| |
| As usual, there were a bunch of other improvements and bugfixes scattered |
| added effect of making the code work as desired under "python -O" in earlier |
| versions of Python. |
| |
| A nifty new feature is that trace functions can now assign to the |
| :attr:`f_lineno` attribute of frame objects, changing the line that will be |
| executed next. A ``jump`` command has been added to the :mod:`pdb` debugger |
| taking advantage of this new feature. (Implemented by Richie Hindle.) |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
| Porting to Python 2.3 |
| ===================== |
| |
| This section lists previously described changes that may require changes to your |
| code: |
| |
| |
| There are a few ways to fix this warning. If you really need a positive number, |
| just add an ``L`` to the end of the literal. If you're trying to get a 32-bit |
| integer with low bits set and have previously used an expression such as ``~(1 |
| << 31)``, it's probably clearest to start with all bits set and clear the |
| desired upper bits. For example, to clear just the top bit (bit 31), you could |
| write ``0xffffffffL &~(1L<<31)``. |
| |
n | .. % The empty groups below prevent conversion to guillemets. |
| |
| * You can no longer disable assertions by assigning to ``__debug__``. |
| |
| * The Distutils :func:`setup` function has gained various new keyword arguments |
| such as *depends*. Old versions of the Distutils will abort if passed unknown |
| keywords. A solution is to check for the presence of the new |
| :func:`get_distutil_options` function in your :file:`setup.py` and only uses the |
| new keywords with a version of the Distutils that supports them:: |
| |
| ext = Extension(**kw) |
| |
| * Using ``None`` as a variable name will now result in a :exc:`SyntaxWarning` |
| warning. |
| |
| * Names of extension types defined by the modules included with Python now |
| contain the module and a ``'.'`` in front of the type name. |
| |
n | .. % ====================================================================== |
n | .. ====================================================================== |
| |
| |
t | .. _acks: |
t | .. _23acks: |
| |
| Acknowledgements |
| ================ |
| |
| The author would like to thank the following people for offering suggestions, |
| corrections and assistance with various drafts of this article: Jeff Bauer, |
| Simon Brunning, Brett Cannon, Michael Chermside, Andrew Dalke, Scott David |
| Daniels, Fred L. Drake, Jr., David Fraser, Kelly Gerber, Raymond Hettinger, |