a1 = b'\x01\x02\x41'
\x41
is A
and when I print str(a1)
, I get
b'\x01\x02A'
how could I get the original hex string?
I want to get:
\x01\x02\x41
I use this string for redis-cli --pipe
.
I don't want python to print the converted string for me.
How could I do it?
now I do like this:
def convert(i:bytes):
result = list()
for j in i:
result.append('\\x%s' % bytes([j]).hex())
return ''.join(result)
It is too ugly. Is there a better way?
btw.
This is my redis-cli --pipe script:
SET "\xda\xb8\xe6\xc0\x79\x62\xea\x06\xde\x9e\xb0\x4e\x68\xde\x0b\x62" "\x00\x42\xdc\x06\x03\x00\x00\x00"
SET "\x68\xfa\xfc\x03\x36\x99\xb0\x56\xb4\x00\xaf\x61\x42\xe0\x30\x42" "\x01\x42\xdc\x06\x03\x00\x00\x00"
SET "\x40\x98\xb9\x8f\xd8\x4e\x2e\x32\x40\x09\xca\xa4\x55\x52\xde\x7f" "\x02\x42\xdc\x06\x03\x00\x00\x00"
SET "\xd0\x75\xdf\x46\x36\xd0\xb4\xed\xcc\xed\xd6\x27\xf7\xd9\xc5\xa5" "\x03\x42\xdc\x06\x03\x00\x00\x00"
I use it this way:
cat sample.redis | redis-cli --pipe