I'm trying to format a string with some \x
inside in python.
When I use:
print '\x00\x00\xFF\x00'
it works nicely and print �
. But when I try to format the string:
print '\x{}\x{}\x{}\x{}'.format('00','00','FF','00')
I get this error:
ValueError: invalid \x escape
The problem when I escape the backslash like this:
print '\\x{}\\x{}\\x{}\\x{}'.format('00','00','FF','00')
It prints:
\x00\x00\xFF\x00
And not the little �
like the non-formatted string.
chr
and bytearray
seem interesting for example:
print chr(0x00),chr(0x00),chr(0xFF),chr(0x00)
or print bytearray([0x00, 0x00, 0xFF, 0x00])
prints �
, but when I try to format them, I get a SyntaxError.
I found some interesting posts like:
But I'm still stuck...
How to print a formatted string with \x
inside?
(I'm using python 2.7 but I can use an other version.)
Thank you