[Bulk] Re: Python 3

Gordon Tyler gordon.tyler at gmail.com
Wed Jun 23 18:28:19 BST 2010


On 23/06/2010 11:45 AM, John Arbash Meinel wrote:
> There are also things like diff headers, where it is a bit more unclear
> whether it is valid to have them as Unicode. (even though users see them)

This is perhaps due to my being a Java programmer for 10 years but it
seems quite logical to have the internal representation of a string in
Unicode and encode that to the required encoding when it "exits" the
application, i.e. written to stdout/file/socket/etc.

Of course, it may be tricky getting an external input into Unicode if
you're not certain what the encoding is.

> I also don't know how long __unicode__ has existed, but certainly in the
> *bzrlib* codebase we haven't done unicode(exception) we've done
> str(exception).

Apparently unicode(exception) won't do what you want it to do:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/f3d0a1f554583eac

> This also gets a bit messy when dealing with OS errors. Where it is very
> common to have the OS return a localized error message in some 8-bit
> string, which we then want to combine with say a Unicode path.

The boilerplate to convert to unicode could be a somewhat tiresome, I
suppose. Although, would it not be possible to monkeypatch Exception to
add a __unicode__ method that does the right thing?

Ciao,
Gordon



More information about the bazaar mailing list