I have this string with unicode sequences, something like
"\\u0020dfhbafhfka\\u0022dahjfdsakj\\u005Dbty"
for example. I would like to encode the unicode sequences, so the output is something like this: idfhbafhfka"dahjfdsakj]bty
, where \\u0020 is encoded to a space, \\u0022 is encoded to a ", and \\u005D is encoded to a ]. If I run this:
print("\u0020".encode("UTF-8))
I get a space, which is correct. But, if I run this (string = the unicode sequence):
print(string[1:7].encode("UTF-8"))
I get this:
b'\\u0020'
I cut off the first backslash, because in the unicode sequences there is only one backslash. Also, make sure the string has literal backslashes, because if you input the string literally, the backslashes are escape sequences. One way of doing this is setting a variable to backslash with chr(92) and then putting it everywhere there is a backslash. Any help is appreciated