I'm writing a program in Python 3.4.1 that uses PySerial to test some hardware.
Bytes are read from the serial port one at a time, and then appended to list. When the list reaches a certain size, it is sent for processing. Depending on the incoming data, the data sometimes has to be processed before the list is full, hence byte-by-byte operation.
The list then comes back as:
[b'F', b'o', b'o']
For part of the test script, I need to be able to convert this to a string, so that I can just print:
Foo
My solution is:
b''.join([b'F', b'o', b'o']).decode("ascii")
But it just feels wrong. Is there a better approach to this?
If you don't like how
join
looks, you can do following:It's almost the same thing as in your code. I don't think you'll find any better approach.