A question on Encoding and Decoding.
Johan von Boisman
do-not-reply at by-mail.com
Fri Nov 17 11:18:41 CET 2006
rbsharp at gmx.de wrote:
> I think this remark is more to the point. In my experience, the general
> problem is that python operates with the default encoding "ascii" as in
> sys.getdefaultencoding(). It is possible to set the defaultencoding in
> sitecustomize.py, with sys.setdefaultencoding('latin1'). I have placed
> sitecustomize.py in Lib/site-packages. It is not possible to set the
> encoding once python has started. Setting the encoding only works if
> you can bind yourself to this one encoding and is therefore no general
> The only reasonable way to work is to get your strings into unicode
> (and sometimes back out again).
> If for instance you type:
> s = "äÄöÖüÜß" and then try
> us = unicode(s) you will get a traceback identical to yours.
I missed the beginning of this thread, but why not write
s = u"äÄöÖüÜß"
Is there ever a reason _not_ to exclusively use the unicode stringtype
throughout your Python program? (of course you may need to encode/decode
when interfacing with the world outside your program)
More information about the Python-list