unicode encoding usablilty problem

Walter Dörwald walter at livinglogic.de
Fri Feb 18 14:18:28 EST 2005


aurora wrote:

 > [...]
> In Java they are distinct data type and the compiler would catch all  
> incorrect usage. In Python, the interpreter seems to 'help' us to 
> promote  binary string to unicode. Things works fine, unit tests pass, 
> all until  the first non-ASCII characters come in and then the program 
> breaks.
> 
> Is there a scheme for Python developer to use so that they are safe 
> from  incorrect mixing?

Put the following:

import sys
sys.setdefaultencoding("undefined")

in a file named sitecustomize.py somewhere in your Python path and
Python will complain whenever there's an implicit conversion between
str and unicode.

HTH,
    Walter Dörwald



More information about the Python-list mailing list