title: Python writing function output to a file
body: <p>I have a function that simulates something and writes the resulting array to a text file. </p>
  
  <p>For example,</p>
  
  <pre><code>def SimulationFunction(args):
      #some simulation which results simOUT
      f = open('results.txt','w')
      f.write(str(simOUT) + '\n')
      f.close()
  </code></pre>
  
  <p>I would like run the function on varying input arguments and save the outputs to the new lines of the same results.txt file.</p>
  
  <p>For example,</p>
  
  <pre><code>for i in inputArgs:
      SimulationFunction(i)
  </code></pre>
  
  <p>However, when I try to run this, the resulting text file only 
  contains the results from the last simulation run.</p>
  
  <p>What am I missing here?
  Any suggestions would be greatly appreciated!</p>