ElementTree: How to return only unicode?

Torsten Bronger bronger at physik.rwth-aachen.de
Sat Mar 14 18:06:22 EDT 2009


Hallöchen!

Stefan Behnel writes:

> Torsten Bronger wrote:
>
>> [...]
>> 
>> My problem is that if there is only ASCII, these methods return
>> ordinary strings instead of unicode.  So sometimes I get str,
>> sometimes I get unicode.  Can one change this globally so that
>> they only return unicode?
>
> That's a convenience measure to reduce memory and processing
> overhead.

But is this really worth the inconsistency of having partly str and
partly unicode, given that the common origin is unicode XML data?

> Could you explain why this is a problem for you?

I feed ElementTree's output to functions in the unicodedata module.
And they want unicode input.  While it's not a big deal to write
e.g. unicodedata.category(unicode(my_character)), I find this rather
wasteful.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
                   Jabber ID: torsten.bronger at jabber.rwth-aachen.de



More information about the Python-list mailing list