[FRPythoneers] Question about string.join method

J. Wayde Allen wallen at its.bldrdoc.gov
Mon Apr 30 11:30:39 MDT 2001


Friday I was tinkering with the following piece of code to extract
latitude, longitude, time, and elevation data from the NMEA data stream
put out by a GPS receiver.  What I have below seems to work
fine.  However, I had originally thought that the line

           self.latitude = field[2] + field[3]

should read

           self.latitude = string.join(field[2], field[3])

When I do that the numbers in field[2] = "4009.120" and the letter
in field[3] = "N" get interleaved resulting in 

           self.latitude == "4N0N0N9N.N1N2N0"

I had thought that the strin.join method was supposed to append these
fields together with an intermediate space.  The desired result would have
been

           self.latitude == "4009.120 N"

So, what am I missing here?  Adding the strings as I've done seems to
work, but I'm not sure why?

- Wayde
  (wallen at lug.boulder.co.us)
----------------------------------------------------------------------------

#!/usr/bin/env python

import string

class nmeafile:

   def __init__(self, filename):
      self.filename = filename

      for line in open(self.filename, 'r').readlines():
         if line[:6] == '$GPGGA':
            field = string.split(line,",")
            self.time = field[1]
            self.latitude = field[2] + field[3] 
            self.longitude = field[4] + field[5]
            self.quality = field[6]
            self.num_svs = field[7]
            self.hdop = field[8]
            self.altitude = field[9] + field[10]

            print self.time, self.latitude, self.longitude, self.altitude
            
         
if __name__ == '__main__':
   
   print 'Time Latitude Longitude Elevation'   
   gps = nmeafile('gpsdatafile')
            





More information about the FRPythoneers mailing list