How to do special encode in string ?

Andrew Bennetts andrew-pythonlist at puzzling.org
Thu Jun 24 08:52:50 EDT 2004


On Tue, Jun 22, 2004 at 02:39:36PM +0200, fowlertrainer at anonym.hu wrote:
[...]
> 
> Example:
> Encode("az állam én vagyok") -> "az \xe1llam \xe9n vagyok"
> 
> Decode("az \xe1llam \xe9n vagyok") -> "az állam én vagyok"

You want the decode and encode methods of the str and unicode types,
respectively:

>>> u = "az \xe1llam \xe9n vagyok".decode('latin-1')
>>> type(u)
<type 'unicode'>
>>> print u
az állam én vagyok
>>> u.encode('latin-1')
'az \xe1llam \xe9n vagyok'

-Andrew.





More information about the Python-list mailing list