Reputation: 47
i have the following string of hex bytes from a smart meter:
'~\xa0\x1e\x03\x00\x02\xfe\xff4\xca\xec\xe6\xe7\x00\xc4\x01A\x00\x02\x04\x12\x00\x05\x11\x01\x11\x01\x11\x00\xc7\x11 ~'
I want to separate them in a list and then pass them to decimals or int. The .split() python function won't work, any ideas?
thanks!
Upvotes: 0
Views: 851
Reputation: 22314
You can convert a string to a list of ascii values with ord
.
values = [ord(c) for c in data]
Although, depending on what you want to do, you might not even need to cast your data as a list
since a str
is already iterable.
Instead, iterate over your characters and recover their value. Here is a simplified example.
dt = '\xa0\x1e\x03\x00\x02\xfe'
for x in map(ord, dt):
print(x)
160
30
3
0
2
254
Upvotes: 1