How to get Python to default to UTF8

"Martin v. Löwis" martin at v.loewis.de
Sun Dec 23 18:27:20 EST 2007


> However, the situation is still unacceptable to me because I often make 
> mistakes and it is easy for me to miss places where encoding is necessary. I 
> rely on testing to find my faults. On my development environment, I get no 
> error message and it seems that everything works perfectly. However, once 
> ported to the server, I see a crash. But this is too late a stage to catch 
> the error since the app is already live.

If you want to check whether there is indeed no place where you forgot
to properly .encode, you can set the default encoding on your
development machine to "undefined" (see site.py). This will give you an
exception whenever the default encoding is invoked, even if the encoding
would have succeeded under the default default encoding (ie. "ascii")

Such a setting should not be applied a production environment.

> Can you elaborate on where to look to see what stdin/stdout encodings are 
> set to?

Just print out sys.stdin.encoding and sys.stdout.encoding. Or were you
asking for the precise source in the interpreter that sets them?

> All inputs are coming at my app either via html forms or input 
> files. All output goes either to the browser via html or to an output file.

Then sys.stdout.encoding will not be set to anything.

Regards,
Martin



More information about the Python-list mailing list