py-serial + CSV

McBooCzech petr at tpc.cz
Tue Aug 23 20:00:32 CEST 2005


Sorry, I did not mentioned the data flow from the serial port is
permanent/continuous (as long as the GPS receiver is connected to the
serial port). The input data are commning every second, they are comma
separated and they are looking like:

$GPGGA,174525.617,5026.1080,N,01521.6724,E,1,05,1.8,306.5,M,,,,0000*0B
$GPGSA,A,3,02,09,05,06,14,,,,,,,,3.6,1.8,3.1*31
$GPGSV,3,1,09,30,74,294,,05,65,093,49,06,40,223,32,02,39,089,49*78
$GPRMC,174525.617,A,5026.1080,N,01521.6724,E,0.0,005.8,230805,,*0A
etc....

>From the rows they are begining with $GPRMC I want to get following
data only (positions 2,4,6)
174525.617
5026.1080
01521.672

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.
--
Petr Jakes




More information about the Python-list mailing list