I'm trying to read a byte object from a text file, but whenever I read from the text file I get double backslashes in the bytes object and I cannot find out how to revert them to single backslashes. The file is opened as open(file, 'rb')
. I've tried using encode and decode and I've also tried using eval(str(my_string).replace('\\\\','\\'))
as detailed in other answers, but all have returned the error: SyntaxError: (value error) invalid \x escape at position 372
. The string I am trying to read is: \xde\xcct\x18\xe5*\x91\xcc\xf1\xb4\xe9\xc2\x97BhR\x87\xd6x\xd8\x83\x8b\xc2\x08
Edit:
The answers detailed in Reading utf-8 escape sequences from a file and other questions haven't helped, since I still get a unicode escape error when trying the methods.