I use Python 2.7.X.
I have a text file with the following content:
\xe87\x00\x10LOL
Note that this is the text itself, and not its binary representation (meaning the first char is '\\', not 0xe8) When I read it (as binary), I get:
a = "\\\\xe87\\\\x00\\\\x10LOL"
because it is a text file.
I want to convert it to a binary form, meaning I want to get a file which begins with the characters
0xe8, 0x37, 0x00, 0x10, 0x4c, 0x4f, 0x4c.
(Note that 0x4c == 'L', 0x4f == 'O').
How do I do that?
Tried all sorts of solutions like hexlify\unhexlify, int(c, 16), but it seems like I'm missing something.
Also note that the length of the file varies, so struct.pack is less preferred.