replace text in unicode string

Dan Bishop danb_83 at yahoo.com
Sat May 14 05:23:55 EDT 2005


Svennglenn wrote:
> I'm having problems replacing text in a
> unicode string.
> Here's the code:
>
> # -*- coding: cp1252 -*-
>
> titel = unicode("ä", "iso-8859-1")
> print titel
> print type(titel)
>
> titel.replace("ä", "a")
>
> When i run this program I get this error:
>
>     titel.replace("ä", "a")
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position
0:
> ordinal not in range(128)
>
> How can i replace text in the Unicode string?

titel = titel.replace(u"ä", "a")




More information about the Python-list mailing list