string interpolation mystery in Python 2.6

Alan G Isaac alan.isaac at gmail.com
Sat Sep 12 00:12:22 CEST 2009


Michael Foord came up with a much simpler
illustration.  With Python 2.6::

         >>> try:
         ...  open('flooble')
         ... except Exception as e:
         ...  pass
         ...
         >>> e
         IOError(2, 'No such file or directory')
         >>> unicode(e)
         u"(2, 'No such file or directory')"
         >>> str(e)
         "[Errno 2] No such file or directory: 'flooble'"
         >>> u'%s' % e
         u"(2, 'No such file or directory')"
         >>> '%s' % e
         "[Errno 2] No such file or directory: 'flooble'"

Cheers,
Alan Isaac




More information about the Python-list mailing list