How to do special encode in string ?

Christopher Koppler klapotec at chello.at
Mon Jun 21 15:46:42 EDT 2004


On 21 Jun 2004 10:14:57 GMT, Duncan Booth <me at privacy.net> wrote:

>"fowlertrainer at anonym.hu" <fowlertrainer at anonym.hu> wrote in 
>news:mailman.88.1087811553.454.python-list at python.org:
>
>> Encode("az állam én vagyok") -> "az \xe1llam \xe9n vagyok"
>> 
>> Decode("az \xe1llam \xe9n vagyok") -> "az állam én vagyok"
>> 
>
>>>> s = "az \xe1llam \xe9n vagyok"
>>>> print s.decode('latin-1')
>az állam én vagyok
>>>> 
>
>You want to use unicode strings if you have characters outside the ASCII 
>range. The decode method on a byte string will let you convert it to a 
>unicode string, and the encode method will let you convert it back to byte 
>string.
>
>The tricky bit is that you need to know the correct encoding to use as \xe1 
>could mean different characters, but in this case it looks as though you 
>meant latin-1.

For Hungarian long umlauts, you'll want to use latin-2 (or iso8859-2).


--
Christopher



More information about the Python-list mailing list