how can I convert invalid ASCII string to Unicode?
Mark Hammond
MarkH at ActiveState.com
Wed May 9 01:14:45 EDT 2001
skip at pobox.com 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
'\x94'
>>> unicode(s, "Latin-1")
u'\x94'
>>>
Mark.
More information about the Python-list
mailing list