Use exception handling and skip the lines, which do not have enough fields.
import serial def do_something(a, b): print(a, b) def read_loop(ser): while True: dat = ser.readline().decode() localtime = time.asctime(time.localtime(time.time())) try: a,b,c,d,e,f,g,h = dat.split(" ; ") except ValueError: print('Incomplete data, skipping') do_something(a, b) with serial.Serial('/dev/ttyACM0', 9600) as ser: ser.flushInput() read_loop(ser)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!