Currently I work on a project with an NFC tag reader. All data is stored in decimal values and I managed to track the data I need down and cut every special character out of it. I now want to convert it to ascii so it prints out a readable version of the data.
The variable setvar is a string and has the value "84 97 103 32 78 117 109 98 101 114 32 49"
This is the code I try to use:
print "ASCII value: ", ´,´.join(str(chr(c)) for c in setvar)
Sadly this produces an error that this function needs integers. Now my next step would be to convert my string to an array(?) and read each item of that array with a loop. Sadly I have no idea how to do that.
How to do that?
I'd just decode the corresponding bytes.
>>> s = "84 97 103 32 78 117 109 98 101 114 32 49"
>>> bytes(map(int, s.split())).decode()
'Tag Number 1'
(Note that decode can take an optional encoding argument, the default value is 'utf-8'.)
You can try this:
print ', '.join(chr(int(i)) for i in setvar.split())
chr will convert any integer to its alphabetical ASCII letter.
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