title: Writing into CSV file using python
body: <p>Here some simple code I have written. Data is not accumulated in the CSV file;
  can someone share code to read data from serial port and log this to a CSV file?</p>
  
  <pre><code>import serial
  import csv
  import string
  import os
  import time
  import sys
  
  def main():
      pass
  
  if __name__ == '__main__':
      main()
      count=0
      f=open("test.txt","w+");
      result = csv.writer(f,delimiter=',', dialect='excel-tab')
  
      result_statememt=("date","zenith","elevation","azimuth","conv_elevation");
      result.writerow(result_statememt)
      f.close()
      while(count&lt;10):
          #time.sleep(60)
          ser=serial.Serial()
          ser.port=3
          ser.baudrate=9600
          ser.open()
          str=ser.read(50)
          val=str.split(":")
          lines=str.split("\r\n")
          count=count+1
          print count
          f=open("test.txt","a+")
          result=csv.writer(f,delimiter=',')
          result.writerow()
          f.close()
  
      f.close()
      ser.close()
  </code></pre>