String.decode()


#1

I am having problems with my code stopping when manipulating a bytearray, using the following code, all works as expected, i.e receiving data from the serial connected device.

import streams
streams.serial()
ser=streams.serial(SERIAL2,baud=38400,set_default=False)
line=ser.readline()
print("::", line)

However, when I use the following code to read the line from the serial device everything stops, without error. I have used this code on previous Python projects successfully?

line=ser.readline().decode(‘utf-8’) [:-1]


#2

Hi @nigelibrown,

Zerynth Python strings are immutable sequences of 8-bit characters so you do not need to decode a byte sequence to convert it to a string, but you can simply try with: str(line).

Anyway in most cases you should be able to work directly with the byte sequence (like what you would do in Python2).