|
Original |
Translation |
|
87
|
The :keyword:`print` statement can now have its output directed to a file-like object by following the :keyword:`print` with ``>> file``, similar to the redirection operator in Unix shells. Previously you'd either have to use the :meth:`write` method of the file-like object, which lacks the convenience and simplicity of :keyword:`print`, or you could assign a new value to ``sys.stdout`` and then restore the old value. For sending output to standard error, it's much easier to write this::
|
|
|
88
|
print >> sys.stderr, "Warning: action field not supplied"
|
|
|
89
|
Modules can now be renamed on importing them, using the syntax ``import module as name`` or ``from module import name as othername``. The patch was submitted by Thomas Wouters.
|
|
|
90
|
A new format style is available when using the ``%`` operator; '%r' will insert the :func:`repr` of its argument. This was also added from symmetry considerations, this time for symmetry with the existing '%s' format style, which inserts the :func:`str` of its argument. For example, ``'%r %s' % ('abc', 'abc')`` returns a string containing ``'abc' abc``.
|
|
|
91
|
|
92
|
Earlier versions of Python used a recursive algorithm for deleting objects. Deeply nested data structures could cause the interpreter to fill up the C stack and crash; Christian Tismer rewrote the deletion logic to fix this problem. On a related note, comparing recursive objects recursed infinitely and crashed; Jeremy Hylton rewrote the code to no longer crash, producing a useful result instead. For example, after this code::
|
|
|
93
|
a = [] b = [] a.append(a) b.append(b)
|
|
|
94
|
The comparison ``a==b`` returns true, because the two recursive data structures are isomorphic. See the thread "trashcan and PR#7" in the April 2000 archives of the python-dev mailing list for the discussion leading up to this implementation, and some useful relevant links. Note that comparisons can now also raise exceptions. In earlier versions of Python, a comparison operation such as ``cmp(a,b)`` would always produce an answer, even if a user-defined :meth:`__cmp__` method encountered an error, since the resulting exception would simply be silently swallowed.
|
|
|
95
|
Work has been done on porting Python to 64-bit Windows on the Itanium processor, mostly by Trent Mick of ActiveState. (Confusingly, ``sys.platform`` is still ``'win32'`` on Win64 because it seems that for ease of porting, MS Visual C++ treats code as 32 bit on Itanium.) PythonWin also supports Windows CE; see the Python CE page at http://pythonce.sourceforge.net/ for more information.
|
|
|
96
|
Another new platform is Darwin/MacOS X; initial support for it is in Python 2.0. Dynamic loading works, if you specify "configure --with-dyld --with-suffix=.x". Consult the README in the Python source distribution for more instructions.
|
|