Unicode problems, yet again

Jp Calderone exarkun at divmod.com
Sat Apr 23 22:22:18 EDT 2005


On Sun, 24 Apr 2005 03:15:02 +0200, Ivan Voras <ivoras at something.ortheother> wrote:
>I have a string fetched from database, in iso8859-2, with 8bit characters, 
>and I'm trying to send it over the network, via a socket:

  You don't have a string fetched from a database, in iso-8859-2, alas.  That is the root of the problem you're having.  What you have is a unicode string.

  It's easy to go from this to what you want (iso-8859-2 encoded string), fortunately.  Just call unicodeStr.encode('iso-8859-2') and write the result over the socket.

>
>(Does anyone else feel that python's unicode handling is, well... suboptimal 
>at least?)

  Hmm.  Not really.  The only problem I've found with it is misguided attempt to "do the right thing" by implicitly encoding unicode strings, and this isn't so much of a problem once you figure things out, because you can always do things explicitly and avoid invoking the implicit behavior.

  Jp




More information about the Python-list mailing list