+ 1
How to convert string to Ascii in python?
My code getting a hex back in a string format but I want to convert it into Ascii. >>> Print(x) 32 2e 45 >>> Print(type(x)) <Class 'str'> So if I go to online hex to Ascii converter and put 32 2e 45 in I get 2.E which is what I want to get. There is no way for me to get the value of x in a hex format. I only can get it in a string format so I don't know how to convert it to ascii to get 2.E I hope this make sense. Thank you for helping.
4 Answers
+ 5
Here is my solution, done with a comprehension:
inp = '32 2e 45'
print(''.join([chr(int(i,16)) for i in inp.split()])) # result: 2.E
+ 2
Lothar more pythonicâș
0
Thanks Frogged this worked for me