title: Making a loop to write new lines to a txt file using python
body: <p>I'm trying to get the script to read a text file of Congress members in which each line is formatted like this: </p>
  
  <p>Darrell Issa (R-Calif) </p>
  
  <p>I want it to print a line to a different file that's formatted like this (notice the added comma):</p>
  
  <p>Darrell Issa,(R-Calif) </p>
  
  <p>For some reason the script below works but it only does it for the first line. How do I get it to execute the loop for each line?</p>
  
  <pre><code>basicfile = open('membersofcongress.txt', 'r')
  
  for line in basicfile:
     partyst = line.find('(')
     partyend = line.find(')')
     party = line[partyst:partyend+1]
     name = line[+0:partyst-1]
     outfile = open('memberswcomma.txt','w')
     outfile.write(name)
     outfile.write(",")
     outfile.write(party)
     outfile.close()
  
  basicfile.close()
  print "All Done"
  </code></pre>
  
  <p>Thank you in advance for your help.</p>