title: Need to generate a new text file and save it every time I run a script in python
body: <p>I currently have a program that appends to an already existing file called "ConcentrationData.txt". However, I would like to create a new text file every time the program is run, preferably with a file name that has the date and time. This is what my current script looks like: </p>
  
  <pre><code>def measureSample(self):
      sys.stdout.flush()
      freqD1, trandD1, absoD1 = dev.getMeasurement(LED_TO_COLOR='D1'])
      freqD2, trandD2, absoD2 = dev.getMeasurement(LED_TO_COLOR='D2'])
      absoDiff= absoD1 - absoD2
      Coeff= 1 
      Conc = absoDiff/Coeff
      Conc3SD = '{Value:1.{digits}f'.format(Value = Conc, digits=3)
      self.textEdit.clear()
      self.textEdit.setText('Concentration is {0}'.format(Conc3SD))
  
      timeStr = time.strftime('%m-%d-%Y %H:%M:%S %Z')
      outFile = open('ConcentrationData.txt','a')
      outFile.write('{0} || Concentration: {1}'.format(timeStr, Conc3SD))
      outFile.close()
  </code></pre>
  
  <p>How would I go about doing that? </p>
  
  <p>(Also, I'm pretty new to python so I'm sorry if this sounds like a silly question).</p>