py-serial + CSV

Grant Edwards grante at visi.com
Tue Aug 23 16:41:04 CEST 2005


On 2005-08-23, McBooCzech <petr at tpc.cz> wrote:

>>>> import serial
>>>> s = serial.Serial(port=0,baudrate=4800, timeout=20)
>>>> s.readline()
> '$GPRMC,101236.331,A,5026.1018,N,01521.6653,E,0.0,328.1,230805,,*09\r\n'
>
> my next intention was to do something like this:
>
> import csv
> r = csv.reader(s.readline())
> for currentline in r:
>     if currentline[0] == '$GPRMC':
>         print currentline[2]
>         print currentline[4]
>
> but it does not work

For something that simple (the data itself doesn't contain any
commas), it's probably easier to use the string's split method
rahter than CSV.  Try something like this:

 line = s.readline()
 words = line.split(',')

-- 
Grant Edwards                   grante             Yow!  Now KEN and BARBIE
                                  at               are PERMANENTLY ADDICTED to
                               visi.com            MIND-ALTERING DRUGS...



More information about the Python-list mailing list