how to replace '1c' to '\x1c' in python. I have a list with elements like '12','13' etc and want to replace with '\x12', '\x13' etc.
here is what i tried and failed
letters=[]
for i in range(10,128,1):
a=(str(hex(i))).replace('0x','\x')
letters.append(a)
print letters
I need is '31' to be replaced by '\x31' ---> '1' not '\x31' 0r \x31
You need to use the built-in function chr to return the correct ascii code (which is the string you are after):
>>> [chr(i) for i in range(10,20,1)]
['\n', '\x0b', '\x0c', '\r', '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With