On Fri, Sep 11, 2009 at 3:12 PM, Alan G Isaac <> wrote:
> 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'"
Sounds like IOError or one of its ancestors defines both __str__() and
__unicode__ () special methods but has them produce different output.
Cheers,
Chris
--
http://blog.rebertia.com