I have a unicode escaped string:

> str = 'blah\\x2Ddude'

I want to convert this string into the unicode unescaped version 'blah-dude'

How do I do this?

有帮助吗?

解决方案

Encode it to bytes (using whatever codec, utf-8 probably works) then decode it using unicode-escape:

s = 'blah\\x2Ddude'

s.encode().decode('unicode-escape')
Out[133]: 'blah-dude'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top