how can I convert invalid ASCII string to Unicode?

Mark Hammond MarkH at
Wed May 9 07:14:45 CEST 2001

skip at wrote:

> I have been blissfully ignoring Unicode.  Alas, my bliss has been so rudely
> interrupted...
> Suppose I have this string:
>     s = "ö"	    # "o" with an umlaut
> and I'd like to convert it to UTF-8.  (I know I can preface string literals
> with 'u', but that's not an option here.  Pretend s was assigned from a file
> read.)
> Simply executing
>     u = unicode(s)

Hi Skip,

Is this what you want?

 >>> s = "ö"
 >>> s
 >>> unicode(s, "Latin-1")


More information about the Python-list mailing list