Unicode problem

"Martin v. Löwis" martin at v.loewis.de
Sun Apr 8 23:21:08 EDT 2007


> Thanks! That's a nice little stumbling block for a newbie like me ;) Is 
> there a way to make utf-8 the default encoding for every string, so that 
> I do not have to encode each string explicitly?

You can make sys.stdout encode each string with UTF-8, with

sys.stdout = codecs.getwriter('utf-8')(sys.stdout)

Make sure that you then that *all* strings that you print
are Unicode strings.

HTH,
Martin



More information about the Python-list mailing list