Re: string interpolation mystery in Python 2.6

2009-09-16 Thread Scott David Daniels
Alan G Isaac wrote: George Brandl explained it to me this way: It's probably best explained with a bit of code: >>> class C(object): ... def __str__(self): return '[str]' ... def __unicode__(self): return '[unicode]' ... >>> "%s %s" % ('foo', C()

Re: string interpolation mystery in Python 2.6

2009-09-12 Thread Alan G Isaac
On 9/11/2009 9:42 PM, Steven D'Aprano wrote: However, I must admit I'm perplexed why the original example is calling __unicode__() in the first place! Given the line: raise self.severe('Problems with "%s" directive path:\n%s: %s.' % (self.name, error.__class__.__name__, error)) it looks to

Re: string interpolation mystery in Python 2.6

2009-09-12 Thread Vlastimil Brom
2009/9/12 Steven D'Aprano : > On Fri, 11 Sep 2009 15:19:05 -0700, Chris Rebert wrote: > >> Sounds like IOError or one of its ancestors defines both __str__() and >> __unicode__ () special methods but has them produce different output. > > > That's what it looks like to me too, which I wouldn't call

Re: string interpolation mystery in Python 2.6

2009-09-11 Thread Steven D'Aprano
On Fri, 11 Sep 2009 15:19:05 -0700, Chris Rebert wrote: > 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:: [snip] > Sounds like IOError or one of its ancestors defines both __str__() and > __unicode__ () spec

Re: string interpolation mystery in Python 2.6

2009-09-11 Thread Chris Rebert
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

Re: string interpolation mystery in Python 2.6

2009-09-11 Thread Alan G Isaac
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 fil

string interpolation mystery in Python 2.6

2009-09-11 Thread Alan G Isaac
MYSTERY: how can "%s"%error be different from "%s"%str(error) in Python 2.6? APOLOGY: I tried to strip this down, but could not find a simple way to reproduce the problem. This way works, however. (There is a discussion on the docutils-develop list.) Although there are several steps, we are ta