py-serial + CSV

Grant Edwards grante at visi.com
Wed Aug 24 10:25:37 EDT 2005


On 2005-08-24, Sybren Stuvel <sybrenUSE at YOURthirdtower.com.imagination> wrote:

>> import serial
>> s = serial.Serial(port=0,baudrate=4800, timeout=20)
>> while 1:
>> 	line = s.readline()
>> 	words = line.split(',')
>> 	if words[0]=="$GPRMC":
>> 		print words[1], words[3], words[5]
>>
>> I just wonder if there is some beter (or as you are saying "more
>> pythonic":) aproach how to write such a piece of code.
>
> You could use regular expressions instead.

  "There is a programmer who has a problem to solve.  He decides
   to use regular expressions.  Now he has two problems."

> And to make it even more pythonic, replace the "while" and the
> "line = s.readline()" with "for line in s:"

Serial port objects aren't iterable.

-- 
Grant Edwards                   grante             Yow!  I was making donuts
                                  at               and now I'm on a bus!
                               visi.com            



More information about the Python-list mailing list