Re: Short confusing example with unicode, print, and __str__

2008-03-06 Thread Peter Otten
Gerard Brunick wrote: > It seems the question is more about what does print do.  Lets extend > your example: > > >>> d=unicode("Caf\xe9", "Latin-1") > >>> repr(d) > "u'Caf\\xe9'" > >>> print d > Café > >>> str(d) > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'a

Re: Short confusing example with unicode, print, and __str__

2008-03-05 Thread Gerard Brunick
Gary Herron wrote: > Gerard Brunick wrote: >> I really don't understand the following behavior: >> >> >>> class C(object): >> ... def __init__(self, s): self.s = s >> ... def __str__(self): return self.s >> ... >> >>> cafe = unicode("Caf\xe9", "Latin-1") >> >>> c = C(cafe) >> >>> print

Re: Short confusing example with unicode, print, and __str__

2008-03-05 Thread Gary Herron
Gerard Brunick wrote: > I really don't understand the following behavior: > > >>> class C(object): > ... def __init__(self, s): self.s = s > ... def __str__(self): return self.s > ... > >>> cafe = unicode("Caf\xe9", "Latin-1") > >>> c = C(cafe) > >>> print "Print using c.s:", c.s > Prin

Short confusing example with unicode, print, and __str__

2008-03-05 Thread Gerard Brunick
I really don't understand the following behavior: >>> class C(object): ... def __init__(self, s): self.s = s ... def __str__(self): return self.s ... >>> cafe = unicode("Caf\xe9", "Latin-1") >>> c = C(cafe) >>> print "Print using c.s:", c.s Print using c.s: Café >>> print "Print using