py-serial + CSV

Sybren Stuvel sybrenUSE at YOURthirdtower.com.imagination
Wed Aug 24 03:54:41 EDT 2005


McBooCzech enlightened us with:
> This (according to your suggestions) is my code which works for me
>
> 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. And to make it even more
pythonic, replace the "while" and the "line = s.readline()" with
"for line in s:"

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
                                             Frank Zappa



More information about the Python-list mailing list