(Jan-24-2021, 10:13 PM)bowlofred Wrote: When you have a regular string, you pass in another string object as text to split on.
>>> "split this, string, on the, commas".split(",") ['split this', ' string', ' on the', ' commas']But if instead of a string you have a bytes object, this won't work.
>>> b"split this, string, on the, commas".split(",") Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: a bytes-like object is required, not 'str'YourarduinoString
is a bytes object. So to split it, the argument has to be a bytes object as well. Instead of","
, useb","
OR convert it to a string and split it as normal.
>>> arduinoString = b"split this, string, on the, commas" >>> arduinoString.split(b",") # split directly on the bytes object [b'split this', b' string', b' on the', b' commas'] >>> arduinoString.decode().split(",") # decode to str, then split the str ['split this', ' string', ' on the', ' commas']Note the result of the split is a list of bytes objects,
This is actually what i needed and worked. I had convert to a number because the tutorial i was following.. puts this into a matplot chart and that was my goal.
for any one else trying to do this here is the link ..Arduino-python to matplot
Note: I use Anaconda with python 3.7 this seems to work for me up to this point. in the tutorial he uses 2.7.