How to disable unicode escaped string in python?

I have a Unicode escaped string:

> str = 'blah\\x2Ddude' 

I want to convert this string to Unicode Unesced version of 'blah-dude'

How can I do it?

+3
source share
1 answer

Encode it to bytes (using any codec, utf-8 may work), then decode it with unicode-escape :

 s = 'blah\\x2Ddude' s.encode().decode('unicode-escape') Out[133]: 'blah-dude' 
+8
source

Source: https://habr.com/ru/post/1259378/


All Articles