I have a numpy bytes array containing characters, followed by b''
, followed by others characters (including weird characters which raise Unicode errors when decoding):
bytes = numpy.array([b'f', b'o', b'o', b'', b'b', b'a', b'd', b'\xfe', b'\x95', b'', b'\x80', b'\x04', b'\x08' b'\x06'])
I want to get everything before the first b''
.
Currently my code is:
txt = []
for c in bytes:
if c != b'':
txt.append(c.decode('utf-8'))
else:
break
txt = ''.join(txt)
I suppose there is a more efficient and Pythonic way to do that.