title: Python 2.7 - find and replace from text file, using dictionary, to new text file
body: <p>I am newbie to programming, and have been studying python in my spare time for the past few months. I decided I was going to try and create a little script that converts American spellings to English spellings in a text file. </p>
  
  <p>I have been trying all sorts of things for the past 5 hours, but eventually came up with something that got me somewhat closer to my goal, but not quite there!</p>
  
  <pre><code>#imported dictionary contains 1800 english:american spelling key:value pairs. 
  from english_american_dictionary import dict
  
  
  def replace_all(text, dict):
      for english, american in dict.iteritems():
          text = text.replace(american, english)
      return text
  
  
  my_text = open('test_file.txt', 'r')
  
  for line in my_text:
      new_line = replace_all(line, dict)
      output = open('output_test_file.txt', 'a')
      print &gt;&gt; output, new_line
  
  output.close()
  </code></pre>
  
  <p>I am sure there is a considerably better way to go about things, but for this script,here are the issues I am having:</p>
  
  <ul>
  <li>In the output file the lines are written on every other line, with a line break between, but the original test_file.txt does not have this. Contents of test_file.txt shown at bottom of this page</li>
  <li>Only the first instance of an American spelling in a line gets converted to English.</li>
  <li>I didn't really want to open output file in append mode, but couldn't figure out 'r' in this code structure.</li>
  </ul>
  
  <p>Any help appreciated for this eager newb!</p>
  
  <p>The contents of the test_file.txt are:</p>
  
  <pre><code>I am sample file.
  I contain an english spelling: colour.
  3 american spellings on 1 line: color, analyze, utilize.
  1 american spelling on 1 line: familiarize.
  </code></pre>