title: How to log data values in a while loop?
body: <p>I am trying to log data values in each loop. My issue is that the code only logs one entry instead of the new TF and TC value each 0.5 second. My relevant code is:</p>
  
  <pre><code>import time  
  import math 
  import os  
  from time import strftime
  import string
  while True:
      Vmid = chan0.voltage
      Vthermistor = (Vsource - Vmid)
      Current = Vmid/Rfixed
      Rthermistor = Vthermistor / Current
      Ratio = Rthermistor / Rref
      print(' Vmid = %6.2f Vthermistor = %6.2f  Current = %8.4e' % (Vmid , Vthermistor, Current))
      X = math.log(Ratio)
      TK = 1/(A1 + B1*X + C1*X*X + D1*X*X*X)
      TC = TK - 273.15
      TF = TC * 1.8 + 32
      print(' Temperatures deg K %6.2f  deg C %6.2f   deg F %6.2f\n' % (TK, TC, TF))
      # hang out and do nothing for a half second
      log = open('log.txt', 'w') #open a text file for logging
      log.write('%s,%f,%f' % (strftime("%H:%M"), TF, TC)) #write to log
      time.sleep(0.5)
  </code></pre>