| Author: | Raymond Hettinger |
|---|---|
| Release: | 3.3a0 |
| Date: | June 06, 2011 |
This article explains the new features in Python 3.3, compared to 3.2.
The math module has a new function:
- log2(): return the base-2 logarithm of x (Written by Mark Dickinson in issue 11888).
The nntplib.NNTP class now supports the context manager protocol to unconditionally consume socket.error exceptions and to close the NNTP connection when done:
>>> from nntplib import NNTP
>>> with nntplib.NNTP('news.gmane.org') as n:
... n.group('gmane.comp.python.committers')
...
('211 1454 1 1454 gmane.comp.python.committers', '1454', '1', '1454', 'gmane.comp.python.committers')
>>>
(Contributed by Giampaolo Rodolà in issue 9795)
The os module has a new pipe2() function that makes it possible to create a pipe with O_CLOEXEC or O_NONBLOCK flags set atomically. This is especially useful to avoid race conditions in multi-threaded programs.
The os module has a new sendfile() function which provides an efficent “zero-copy” way for copying data from one file (or socket) descriptor to another. The phrase “zero-copy” refers to the fact that all of the copying of data between the two descriptors is done entirely by the kernel, with no copying of data into userspace buffers. sendfile() can be used to efficiently copy data from a file on disk to a network socket, e.g. for downloading a file.
(Patch submitted by Ross Lagerwall and Giampaolo Rodolà in issue 10882.)
The os module has two new functions: getpriority() and setpriority(). They can be used to get or set process niceness/priority in a fashion similar to os.nice() but extended to all processes instead of just the current one.
(Patch submitted by Giampaolo Rodolà in issue 10784.)
distutils has undergone additions and refactoring under a new name, packaging, to allow developers to break backward compatibility. distutils is still provided in the standard library, but users are encouraged to transition to packaging. For older versions of Python, a backport compatible with 2.4+ and 3.1+ will be made available on PyPI under the name distutils2.
The Tk GUI and the serve() function have been removed from the pydoc module: pydoc -g and serve() have been deprecated in Python 3.2.
The sys module has a new thread_info() struct sequence holding informations about the thread implementation.
The ssl module has new functions:
- RAND_bytes(): generate cryptographically strong pseudo-random bytes.
- RAND_pseudo_bytes(): generate pseudo-random bytes.
OS/2 and VMS are no longer supported due to the lack of a maintainer.
Windows 2000 and Windows platforms which set COMSPEC to command.com are no longer supported due to maintenance burden.
This section lists previously described changes and other bugfixes that may require changes to your code: