A question on Encoding and Decoding.

Fredrik Lundh fredrik at pythonware.com
Fri Nov 17 06:40:19 EST 2006


Johan von Boisman wrote:

> Is there ever a reason _not_ to exclusively use the unicode stringtype 
> throughout your Python program?

speed and memory use.  in 2.5, the unicode datatype is almost often as 
fast as the string type at the algorithm level, but it's still limited 
by memory bandwidth for certain operations.  it simply takes a bit more 
time to copy two or four times as much data.

but requiring four times as much memory use can be really hurting, in 
some applications, e.g.

     http://effbot.org/zone/celementtree.htm#benchmarks

a good compromise is to use 8-bit strings for ASCII-only strings, and 
Unicode strings for everything else.  ASCII strings mix well with 
Unicode, and you can use (almost) all string methods and other string 
operations on both kind of strings, without problems.

</F>




More information about the Python-list mailing list