Python FAQ suggests the following to change
the default encoding:
import sys
sys.setdefaultencoding(encoding)
However, the module sys (at least at my machine) doesn't have
setdefaultencoding function.
Is there some other way to fix that?
Regards,
Hrvoje Nezic
I can't believe the Python FAQ suggests that! You should stay away from
that routine (though I'll tell you how to use it later :-).
The real question is: what is the interpretation of characters above 128
in your application? Is the string data encoded using Latin-1, UTF-8,
mbcs, etc? You need to be able to answer this question to know how to
treat characters above 128.
> However, the module sys (at least at my machine) doesn't have
> setdefaultencoding function.
>
> Is there some other way to fix that?
You shouldn't do this but....
>>> import sys
>>> reload(sys)
<module 'sys' (built-in)>
>>> sys.setdefaultencoding('mbcs')
>>> str(u'\u00e9')
'\xe9'
Cheers,
Brian
I wrote this entry in the FAQ, and I really meant it. But I said there,
in the FAQ, that it is valid in sitecustomize.py. Ok, this is valid *only*
in the sitecustomize.py.
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ p...@phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.
Fair enough.
Cheers,
Brian