title: Writing all the values to a text file in Python
body: <p>The quantity <code>A</code> is constantly updated. I want to write all the values of <code>A</code> to a <code>.txt</code> file and not just the last value. <code>A=120,100,10</code> where <code>120</code> is the value in the first iteration and <code>10</code> is the value in the last iteration.</p>
  <pre><code>with open('Data_A.txt', 'w') as f:
      writer = csv.writer(f) 
      A=10
      print(A)
      f.writelines('A'+ '\n')
      f.write(str(A))
  </code></pre>
  <p>The current output is</p>
  <pre><code>A
  10
  </code></pre>
  <p>The expected output is</p>
  <pre><code>A
  120
  100
  10
  </code></pre>