unicode encoding usablilty problem

aurora aurora00 at gmail.com
Fri Feb 18 18:56:41 EST 2005


On Fri, 18 Feb 2005 20:18:28 +0100, Walter Dörwald <walter at livinglogic.de>  
wrote:

> 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

That helps! Running unit test caught quite a few potential problems (as  
well as a lot of safe of ASCII string promotion).



More information about the Python-list mailing list