I'm trying to split a binary string of data like this:
trama = b'1 ; 12.0073 ; NAN ; NAN\r\n919.537 ; 1082.14 ; 0\r\n0 ; 850.26 ; NAN\r\n0 ; 0 ; 0\r\n0 ; 0 ; #\r\n1 ; 11.9612 ; NAN ; NAN\r\n933.792 ; 1097.16 ; 0\r\n0 ; 846.597 ; NAN\r\n0 ; 0 ; 0\r\n0 ; 0 ; #\r\n'
What I want is find the # separator because it means that at this point a set of data ends and consequently the following are another different sample.
I want this:
[
['1', '12.0073', 'NAN', 'NAN', '919.537', '1082.14', '0', '0', '850.26', 'NAN', '0', '0', '0', '0', '0'],
['1', '11.9612', 'NAN', 'NAN', '933.792', '1097.16', '0', '0', '846.597', 'NAN', '0', '0', '0', '0', '0']
]
Right now I'm doing all this process:
trama = b'1 ; 12.0073 ; NAN ; NAN\r\n919.537 ; 1082.14 ; 0\r\n0 ; 850.26 ; NAN\r\n0 ; 0 ; 0\r\n0 ; 0 ; #\r\n1 ; 11.9612 ; NAN ; NAN\r\n933.792 ; 1097.16 ; 0\r\n0 ; 846.597 ; NAN\r\n0 ; 0 ; 0\r\n0 ; 0 ; #\r\n'
values = [
i.strip().decode() for i in trama.split()
if i.strip().decode() not in [";"]
]
a, b = [], []
for i in values:
if i != '#':
b.append(i)
else:
a.append(b)
b = []
It works, but I'm sure exists an easier way to do the same. Somebody knows a pythonic way to achieve it?