Is there a way to get utf-8 out of a Unicode string?
Gerrit Holl
gerrit at nl.linux.org
Mon Oct 30 02:31:52 EST 2006
Hei,
On 2006-10-30 08:25:41 +0100, thebjorn wrote:
> def unfk(s):
> return eval(repr(s)[1:]).decode('utf-8')
>
> i.e. chopping off the u in the repr of a unicode string, and relying on
> eval to interpret the \xHH sequences.
>
> Is there a less hack'ish way to do this?
Slightly lack hackish:
return ''.join(chr(ord(c)) for c in s)
Gerrit.
More information about the Python-list
mailing list