str vs unicode

John Arbash Meinel john at arbash-meinel.com
Fri May 27 11:12:41 UTC 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/27/2011 12:04 PM, Andrew Bennetts wrote:
> 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.  IIRC you can actually return unicode from __str__ in
> Python 2 (probably due to the pervasive str/unicode confusion there).
> 
> -Andrew.

If you return unicode from str it will auto-cast it back to str, and
cause the associated UnicodeEncodeErrors if you have anything that isn't
ascii in the string.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3fhykACgkQJdeBCYSNAAPS2gCfUb4FRYYQZxaaR/1mqDQ7pR7R
RhkAoLhx3iB2mufR5dj15YfpyGD/Xok4
=v9za
-----END PGP SIGNATURE-----



More information about the bazaar mailing list