I have a string like this "b'\\x00\\x01\\x02\\x03\\x04'"
which represents bytes, and I want to convert it into actual bytes
.
I've tried doing this:
string = "b'\\x00\\x01\\x02\\x03\\x04'"
data = bytes(string[2:-1], "utf-8") # Removing quotes and the b
print(data, type(data))
>>> b'\\x00\\x01\\x02\\x03\\x04' <class 'bytes'>
But the data
bytes have double slashes.
Note:
It works using eval
but for security reasons I won't use it.