문제

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