So I get a list of mentions from twitter, and need to know the index of each mention. To do this I use:
for idx, result in enumerate(mentions, start = 48):
message = result['text']
print idx, message
which returns
48 " first message"
as expected. However, I need to use this index for some serial data that requires me to convert the index into hex. So.. I use:
hidx = hex(idx)
which then returns 0x30. However I need to somehow have this result in the exact format of "\x30" so that I can use serial to write:
serial.write("\x30")
what is the best way to accomplish this? If I keep my hex-converted index code the way it is, I get that pesky extra 0 and no backslash that causes the serial code to actually write serial.write(0x30), which is not what I need. Im hoping to find a way that, because of the for loop, I will receive:
serial.write("\x30")
serial.write("\x31")
serial.write("\x32")
ect. for as many mentions as I need. Is there a way to strip the first zero and add the \? Maybe a better way? Im new to python and serial communication so any help will be much appreciated.