inicio mail me! sindicaci;ón

Updates from Python SVN, part 2

There’s a slight change in the behavior of os.path.splitext because of a bug current versions of Python do have:

[code lang="python"] Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type “help”, “copyright”, “credits” or “license” for more information.

from os.path import splitext splitext(’.cshrc’) (”, ‘.cshrc’) [/code]

becomes:

[code lang="python"] Python 2.6a0 (trunk:54262, Mar 10 2007, 18:06:14) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type “help”, “copyright”, “credits” or “license” for more information.

from os.path import splitext splitext(’.cshrc’) (’.cshrc’, ”) [/code]

You can now pass a TestRunner instance to unittest.main() and run doctest from the command line against your beloved Python with python -m doctest file.py.

Another new feature is open() in ZipFile objects allowing you to read a file inside an archive directly:

[code lang="python"]

import zipfile zf = zipfile.ZipFile(’README.zip’) f = zf.open(’README’) print f.read() Hello [/code]

The tuple() object is great to store struct-like data but it’s accessible only through numeric indexes so in Python 2.6 you can use also named tuples like:

[code lang="python"]

from collections import NamedTuple Point = NamedTuple(’Point’, ‘x y’) p = Point(10, 5) p.x 10 p.y 5 [/code]

It behaves like a normal tuple so you can use it everywhere. See the full documentation.

There’s also a bunch of fixes or additions in networking-related modules like support for LMTP in smtplib, HTTP_REFERER support in CGIHTTPServer and more.

As usual, the very source of information for what’s new are the SVN logs or the NEWS file.

Related posts

  • Updates from Python SVN, Part 12
  • Updates from Python SVN, Part 6
  • Updates from Python SVN, Part 10
  • Updates from Python SVN, Part 11
  • Updates from Python SVN, Part 16
  • Gravatar

    Fuzzyman said,

    March 11, 2007 @ 4:04 pm

    Lawrende - these summaries are really useful and interesting. Thanks for the good work.

    Gravatar

    moreati said,

    March 11, 2007 @ 9:49 pm

    Thankyou, these heads up both informative and interesting. I have one query, in the line Point = NamedTuple(‘Point’, ‘x y’) what is the purpose of the 1st argument, ‘Point’?

    Gravatar

    Lawrence said,

    March 11, 2007 @ 10:32 pm

    @moreati: it’s mostly for documentation purposes. See: http://docs.python.org/dev/lib.....ctory.html

    @Fuzzyman: :-)

    Gravatar

    TZOTZIOY said,

    March 14, 2007 @ 6:56 pm

    Many times I silently thank Raymond for additions that many people, including me, have considered useful but never took (or had) the time to advocate for them. The NamedTuple is one of them; I will finally be able to get rid of my TupleStruct and use something in the core. Thanks, Raymond!

    Gravatar

    Lawrence said,

    March 14, 2007 @ 7:39 pm

    That’s a great addition indeed but we shall be careful using it everywhere instead of the normal tuple because it’s implemented in Python, not in C as the tuple() type.

    See: http://svn.python.org/view/pyt.....iew=markup

    RSS feed for comments on this post · TrackBack URI

    Leave a Comment