How to do special encode in string ?

Chris King squirrel at wpi.edu
Wed Jun 23 19:46:16 CEST 2004


> Encode("az  llam  n vagyok") -> "az \xe1llam \xe9n vagyok"
> 
> Decode("az \xe1llam \xe9n vagyok") -> "az  llam  n vagyok"

The functions you want are str.encode and str.decode:
"az  llam  n vagyok".encode("string_escape") -> "az \xe1llam \xe9n
vagyok"
"az \xe1llam \xe9n vagyok".decode("string_escape") -> "az  llam  n
vagyok"

If you choose to use Unicode strings instead, use the "unicode_escape"
codec instead of the "string_escape" codec.

A list of the standard encodings is available at
http://docs.python.org/lib/node127.html if you need with some other
format (rot13 is my personal favourite :P).



More information about the Python-list mailing list