Lenny Domnitser’s
domnit.org

⇙ Jump to content

explicit

This is a static archive of the domnit.org blog,
which Lenny Domnitser wrote between 2006 and 2009.

What’s Shockingly New In Python 2.5

Python 2.5 was released yesterday. Notably, this is the first release of Python since Python creator and Benevolent Dictator for Life Guido van Rossum joined Google.

The release came with the classic what’s new document. Strangely missing from the documentation, however, is a new and undeniably useful feature added to urllib. Back in the stone age of Python 2.4, you actually had to know the URL of whatever data you were retrieving with urllib. That may be acceptable on Web 1.0, but then you might as well be writing Java. Here’s the new way to do it. About damned time if you ask me.

>>> import urllib
>>> f = urllib.urlopen('miserable failure')
>>> print f.geturl()
http://www.whitehouse.gov/president/gwbbio.html

Other open source projects such as Firefox have already benefited from adding this functionality. Under the hood, this is just an I’m Feeling Lucky search, but all you have to know is that Python finally supports The Internet.

By the way, I was joking. But my joke comes with an implementation. Example usage:

>>> # Add these two magic lines:
>>> import lucky
>>> lucky.magic()
>>> # Continue as before:
>>> import urllib
>>> f = urllib.urlopen('miserable failure')
>>> print f.geturl()
http://www.whitehouse.gov/president/gwbbio.html

Download: lucky.py.