Extra 'u' characters in error messages

Fredrik Lundh fredrik at pythonware.com
Thu Apr 14 13:32:23 BST 2005


Nicholas Nethercote wrote:

> I just started looking at Bazaar-NG.  It looks pretty nice.
>
> One minor thing: I noticed that many of the error messages have extra 'u' characters in them, eg:
>
>   [~/bzr/test1] bzr log foo
>   bzr: error: extra arguments to command log: [u'foo']
>   (see $HOME/.bzr.log for debug information)
>   [~/bzr/test1] bzr no_such_command
>   bzr: error: unknown command u'no_such_command'
>   (see $HOME/.bzr.log for debug information)
>
> I don't know what the problem is here.

code that uses repr() on unicode strings.

it might be a good idea to add a helper function that does something like:

    preferred_encoding = locale.get...

    def nicerepr(value):
        if isinstance(value, unicode):
            return repr(value.encode(preferred_encoding, "replace"))
        if isinstance(value, list):
            return repr(map(nicerepr, value))
        return repr(value)

and use this instead of repr() and %r, where applicable.

</F> 







More information about the bazaar mailing list