title: Save coordinates extracted from NMEA log file in a CSV file
body: <p>As a beginner in Python I am dealing with a task. The task is developing a program that reads the NMEA log files via a virtual port and:</p>
  
  <ul>
  <li>printing only "GPGGA" lines</li>
  <li>printing coordinates (lat,lon) from these "GPGGA" lines</li>
  <li>extracting these coordinates in a CSV file</li>
  <li>extracting these coordinates in a KML file</li>
  </ul>
  
  <p>My code is followed:</p>
  
  <pre><code>import serial
  from pynmea import nmea
  import csv
  
  ser=serial.Serial('COM4')
  ser.baudrate=4800
  f = open('coord_list.csv', 'w+')
  print('Waiting for data')
  while True:
      try:     
          message = ser.readline().decode() 
          message = message.strip()     
             if '$GPGGA' in message:    
                  print(message)
                  gpgga = nmea.GPGGA()
                  gpgga.parse(message)   
                  lat = float(gpgga.latitude)
                  lon = float(gpgga.longitude)
                  print("Lat %f Long %f" % (lat, lon))
                  for i in message:
                      coord_list = []
                      coord = [gpgga.latitude,gpgga.longitude]
                      coord_list.append(coord)
                      f.write(coord_list)
                      f.close()
  
      except KeyboardInterrupt:
          raise
  ser.close()
  </code></pre>
  
  <p>For the first two bullets a sample output is like:</p>
  
  <pre><code>Waiting for data
  $GPGGA,170609.941,5335.6665,N,01021.2637,E,1,09,01.1,35.9,M,40.2,M,,*58
  Lat 5335.666500 Long 1021.263700
  $GPGGA,170610.941,5335.6665,N,01021.2637,W,1,09,01.1,36.0,M,40.2,M,,*5A
  </code></pre>
  
  <p>With this code I got an error:</p>
  
  <pre><code>f.write(coord_list)
  TypeError: write() argument must be str, not list   
  </code></pre>
  
  <p>I get stuck on saving coordinates under a CSV file. I couldn't figure out how to write a correct code to solve it. Whatever I tried I got another errors or nothing.  </p>