title: Having trouble using a dictionary to write text file?
body: <pre><code>text = open('samiam.txt', 'r+')
  replacement = {" i ": " I ", "-i-": "-I-"}
  new_file = open('newfile.txt', 'w')
  
  for line in text:
      for k in replacement.items():
          line.replace(k, v)
          new_file.write(line)
  
  
  text.close()
  new_file.close()
  </code></pre>
  
  <p>I run it, it says <code>v</code> isn't defined. If I rewrite it <code>for k, v</code> then it doesn't have this error, but then the file doesn't change. The text file is just <code>sam-i-am</code>, with the <code>i</code>'s all lowercased. I'm trying to uppercase them and rewrite it. But can't quite seem to figure it out.</p>