Python 3 …. default is utf-8 ……..
Arduino (C++) sends numbers over the serial monitor to Python. I want the numbers from C++ as numbers; I sort the by size and put them in a SQLite datbase as integers.
In_data = int (in_data) #. (it has worked but I changed computers (Windows to Mint) and now it gives me an error) print type (in_data) #gives “Unicode”. I think the Unicode includes spaces or something. I tried treating in_data as a string and got an error.
(data_object.inWaiting()>0) unix = (datetime.datetime.now()) in_data = data_object.readline().decode('ascii') #this last part is to pull out the extra junk. # print (type(in_data)) # this is 'unicode" whatever that is (the print works)
print (in_data)######DID NOT WORK print (in_data) print (in_data) print (in_data) print (in_data) print (in_data) print (in_data) print (in_data) print (in_data) print (in_data) print () lstrip(in_data) ###THIS DID NOT WORK rstrip(in_data) print (in_data) ## this goes out to the python monitor; every number print type(in_data)# this works and tells me it is 'unicode'
This has worked: in_data = int (in_data) and the integer logic in Python worked. Now it gives me an error. I think that the field includes a space. "Let's treat it as a string and take out the space." Did not work. "lstrip()' and 'rstrip()' seemed promising, but no.