[Python-Dev] unicode and str (original) (raw)
"Martin v. Löwis" martin at v.loewis.de
Mon Aug 30 22:57:36 CEST 2004
- Previous message: [Python-Dev] unicode and __str__
- Next message: [Python-Dev] unicode and __str__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Neil Schemenauer wrote:
Also, I'm a little unclear on the purpose of the unicode method. If you can return unicode from str then why would I want to provide a unicode method? Perhaps it is meant for objects that can either return a unicode or a string representation depending on what the caller prefers. I have a hard time imagining a use for that.
It's what unicode() returns:
class A: ... def str(self):return "1" ... def unicode(self): return u"2" ... a=A() str(a) '1' unicode(a) u'2'
str() is guaranteed to return a byte string; unicode() is guaranteed to return a unicode string.
Regards, Martin
- Previous message: [Python-Dev] unicode and __str__
- Next message: [Python-Dev] unicode and __str__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]