[FRPythoneers] Question about string.join method

Ken Kinder kkinder at tridog.com
Mon Apr 30 15:09:48 MDT 2001


In python 2.0 you could also do:

	'.'.join('192', '168', '2', '2')

PC Drew wrote:
> 
> string.join actually joins strings together based on a third delimiter:
> 
> string.join(('192', '168', '2', '2'), '.')
> 
> would produce a valid ip address of:
> 
> '192.168.2.2'
> 
> You sent it a string, and since python thinks of strings as arrays of
> chars, it joined every letter in the string with the contents of field[3].
> 
> --On Monday, April 30, 2001 11:30:39 -0600 "J. Wayde Allen"
> <wallen at its.bldrdoc.gov> wrote:
> 
> >
> > 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')
> >
> >
> >
> > _______________________________________________
> > This message sent by the FRPythoneers mailing list.
> > Unsubscribe: echo unsubscribe |
> > FRPythoneers-request at lists.community.tummy.com URL:
> > http://lists.community.tummy.com/mailman/listinfo/frpythoneers
> 
> --
> PC Drew
> 
>    Be nice, or I'll replace you with a very
>    small shell script
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe | FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers

-- 
Ken Kinder
Engineer
Tridog Interactive, Inc.



More information about the FRPythoneers mailing list