title: How do I pass the contents of an list into an existing file?
body: <pre><code>exchangerates = []
  newrate = float(input("Enter amount:"))
  with open("ExchangeRates.txt","r") as readfile:
      for line in readfile:
          exchangerates.append(line.strip().split(","))
          for line in exchangerates:
              if line[0] == currency1 and line[1] == currency2:
                  line[2] = newrate
                  print("The exchange rate for",currency1,"and",currency2,"has been changed to",newrate)
          next
          return 0
  </code></pre>
  
  <p>This code works, but I need to know how to pass the information from the list created above, into the file, shown as "Exchangerates.txt". How would I do this?</p>
  
  <p>sample input and output:</p>
  
  <p>Enter currency 1:Yen</p>
  
  <p>Enter currency 2:Dollar</p>
  
  <p>Enter amount:3</p>
  
  <p>The exchange rate for Yen and Dollar has been changed to 3.0</p>
  
  <p>This is what happens in my code, which is expected. However it does not write to the file and the information is not changed within the file, this is my problem.</p>