I have a sequence of raw unicode that was saved into a str variable:
s_str: str = "\x00\x01\x00\xc0\x01\x00\x00\x00\x04"
I need to be able to get the byte literal of that unicode (for pickle.loads)
s_bytes: bytes = b'\x00\x01\x00\xc0\x01\x00\x00\x00\x04'.
Here the solution of using
s_new: bytes = bytes(s_str, encoding="raw_unicode_escape")
was posted, but it does not work for me. Instead of the desired s_bytes, I get
s_not_bytes = b'\\x00\\x01\\x00\\xc0\\x01\\x00\\x00\\x00\\x04'
that has two backslashes (actually representing only one) for each one that it should have.
Also here and here a similar solution is proposed, but it does not work for me either, I end up getting the double backslashes again. Does anyone have an idea of why this might be happening?
Thank you.