Skip to content

Updates from Python SVN, Part 8

Towards Python 3.0

There’s a new shiny feature: you can track what’s going to disappear in Python 3.x with the -3 switch on the command line. See:

[code lang="python"] rhymes@groove % ./python.exe -3 Python 2.6a0 (trunk, May 29 2007, 13:55:02) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> callable(int) main:1: DeprecationWarning: callable() not supported in 3.x True [/code]

Things like coerce(), apply(), callable(), execfile(), reduce(), reload(), dict.has_key() and more have been deprecated.

Python 2.6 supports the new Python 3.0 exception syntax:

[code lang="python"] >>> try: ... raise Exception("something went wrong") ... except Exception as t: ... print t ... something went wrong [/code]

Notice the as keyword. You can know it all by reading the PEP 3110.

Modules

  • The already deprecated rgbimg module is no longer in the standard library and posixfile has been deprecated too, see:

[code lang="python"] >>> import posixfile main:1: DeprecationWarning: The posixfile module is deprecated; fcntl.lockf() provides better locking [/code]

  • gopherlib has been also removed and so is the gopher support from urllib/urllib2.

  • Platform specific macfs, panel, amoeba and stdwin modules have been removed.

  • plat-freebsd2 and plat-freebsd3 directories have been removed.

  • httplib.HTTPSConnection supports a timeout parameter for the underline socket.

  • Some support for swig modules has been added in distutils.

  • .bz2 extension has been added to mimetypes module:

[code lang="python"] Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import mimetypes >>> mimetypes.guess_type("pcre-7.1.tar.bz2") (None, None)

Python 2.6a0 (trunk, May 29 2007, 13:55:02) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import mimetypes >>> mimetypes.guess_type("pcre-7.1.tar.bz2") ('application/x-tar', 'bzip2') [/code]

  • tarfile module supports Unicode input names. A couple of attributes have been added too.

  • urllib.ftpwrapper supports an optional timeout parameter.

  • shlex.split() now has an optional “posix” parameter to work as close as possible as POSIX rules.

Other

All the function objects now have a set of attributes that mirrors func_* into __ * __, see:

[code lang="python"] >>> def f(): pass ... >>> f.func_name 'f' >>> f.name 'f' >>> dir(f) ['call', 'class', 'closure', 'code', 'defaults', 'delattr', 'dict', 'doc', 'get', 'getattribute', 'globals', 'hash', 'init', 'module', 'name', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'str', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name'] [/code]

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • Facebook
  • Twitter
  • Google Bookmarks
  • FriendFeed
  • Google Buzz
  • HackerNews
  • Posterous
  • Reddit
  • Slashdot
  • Tumblr