str vs unicode
Alexander Belchenko
bialix at ukr.net
Fri May 27 12:37:16 UTC 2011
Andrew Bennetts пишет:
> John Arbash Meinel wrote:
>> On 05/27/2011 05:19 AM, Robert Collins wrote:
> […]
>>> Doesn't python3 delete __unicode__ ? In the spirit of having no
>>> compatiblity concerns, after all :)
>>>
>>> -Rob
>>>
>> It deleted __unicode__ because __str__ *is* __unicode__.
>
> Right. I think Rob's issue is how to write code that is simultaneously
> compatible with 2 and 3 with no translation step. In that case I
> suppose __unicode__ == __str__ (or vice versa?) is probably close to
> close enough.
IIUC, you need define both __str__ and __unicode__ for Python2 and then:
def __str__(self):
...
def __unicode__(self):
...
if PYTHON3:
__str__ = __unicode__
More information about the bazaar
mailing list