title: How to delete specific strings from a file?
body: <p>I have a data file (unstructured, messy file) from which I have to scrub specific list of strings (delete strings).</p>
  <p>Here is what I am doing but with no result:</p>
  <pre><code>infile = r&quot;messy_data_file.txt&quot;
  outfile = r&quot;cleaned_file.txt&quot;
  
  delete_list = [&quot;firstname1 lastname1&quot;,&quot;firstname2 lastname2&quot;....,&quot;firstnamen lastnamen&quot;]
  fin=open(infile,&quot;&quot;)
  fout = open(outfile,&quot;w+&quot;)
  for line in fin:
      for word in delete_list:
          line = line.replace(word, &quot;&quot;)
      fout.write(line)
  fin.close()
  fout.close()
  </code></pre>
  <p>When I execute the file, I get the following error:</p>
  <pre><code>NameError: name 'word' is not defined
  </code></pre>