[Python-Dev] Re: [I18n-sig] Unicode experience

Fredrik Lundh fredrik@pythonware.com
Fri, 7 Jul 2000 14:30:51 +0200


guido wrote:
> I propose ustr(x) with the semantics given by Toby. 

+1 on concept.

not sure about the name and the semantics.

maybe a better name would be "unistr" (to match "unistr").
or maybe that's backwards?

how about "String" (!).

(the perfect name is "string", but that appears to be reserved
by someone else...)

as for the semantics, note that __str__ is allowed to return a
unicode string in the current code base ("str" converts it to 8-
bit using the default encoding).  ustr/unistr/String should pass
that one right through:

    def ustr(s):
        if type(s) in (type(""), type(u"")):
            return s
        s = s.__str__()
        if type(s) in (type(""), type(u"")):
            return s
        raise "__str__ returned wrong type"

> Class support (an __ustr__ method, with fallbacks on __str__
> and __unicode__) would also be handy.

-0 on this one (__str__ can already return either type, and if the
goal is to get rid of both unichr and unistr in the future, we shouldn't
add more hooks if we can avoid it.  it's easier to remove stuff if you
don't add them in the first place ;-)

</F>