Unicode problem
Georg Brandl
g.brandl at gmx.net
Mon Apr 9 03:46:13 EDT 2007
Martin v. Löwis schrieb:
>> 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.
BTW, any reason why an EncodedFile can't act like a Unicode writer/reader object
if one of its encodings is explicitly set to None?
IMO the docs don't make it clear that getwriter() is the correct API to use
here. I've wanted to write "sys.stdout = codecs.EncodedFile(sys.stdout,
'utf-8')" more than once.
Georg
More information about the Python-list
mailing list