title: How to write the result of a calculation to a file in python?
body: <p>I'm doing some calculations after reading a file, and want to store the result (a single number) to another file. I want to be able to do things with this file later. I'm having problems storing the result into the text file.</p>
  
  <p>I tried this:</p>
  
  <pre><code>    c = fdata_arry[:,2]*fdata_arry[:,4] 
      d = np.sum(c)
      print d
      f = open('test','w')
      f.write(d) 
      f.close()
  </code></pre>
  
  <p>which gives me this error for the line <code>f.write(d)</code>: </p>
  
  <blockquote>
    <p>Non-character array cannot be interpreted as character buffer</p>
  </blockquote>
  
  <p>I also tried using <code>np.savetxt('test.dat',d)</code> but that gives me: </p>
  
  <blockquote>
    <p>IndexError: tuple index out of range</p>
  </blockquote>
  
  <p>Any idea how can I solve this? Note that <code>d</code> is just a single value, which is the sum of a few numbers. </p>