py-serial + CSV
Sergei Organov
osv at javad.ru
Tue Aug 23 14:52:35 EDT 2005
Steve Holden <steve at holdenweb.com> writes:
> McBooCzech wrote:
[...]
> > $GPRMC,174525.617,A,5026.1080,N,01521.6724,E,0.0,005.8,230805,,*0A
> > etc....
> >
>
[...]
> > 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.
>
> That code is quite tidy. You could save yourself the split on lines
> that weren't of interest, though frankly this isn't essential - this
> task won't use 1% of CPU on almost any computer built in the last five
> years. But, if you are interested in seeing other solutions you might
> consider it, and it does avoid the split when it's not necessary.
>
>
> while 1:
> line = s.readline()
> if line.startswith("$GPRMC"):
"$GPRMC," would be better, -- not to match something like "$GPRMC174...".
--
Sergei.
More information about the Python-list
mailing list