title: Replacing multiple words in a text file and writing new text to output file
body: <p>I am trying to write a function which takes a text file as input file and create an output file with the same text with words replaced. This function will edit Emma with George, she with he and her with his. </p>
  
  <p>My code is:</p>
  
  <pre><code>switch = {"Emma":"George", "she":"he", "hers":"his"}
  
  def editWords(fin):
      #open the file
      fin = open(filename, "r")
      #create output file
      with open("Edited.txt", "w") as fout:
          #loop through file
          for line in fin.readlines():
              for word in switch.keys():
                  if word in line.split():
                      line = line.replace(word, switch[word])
                  fout.write(line)
      fin.close()
  </code></pre>
  
  <p>The out put file is created however blank.</p>
  
  <p>Does anyone know how to get the output file with the edited text?</p>