title: KeyError: '\\documentclass'
body: <p>I have the following Python script:</p>
  
  <pre><code>import nltk
  from nltk.probability import FreqDist
  nltk.download('punkt')
  
  frequencies = {}
  book = open('book.txt')
  read_book = book.read()
  words = nltk.word_tokenize(read_book)
  frequencyDist = FreqDist(words)
  
  for w in words:
      frequencies[w] = frequencies[w] + 1 
  
  print (frequencies)
  </code></pre>
  
  <p>When I try to run the script, I get the following:</p>
  
  <pre><code>[nltk_data] Downloading package punkt to /home/abc/nltk_data...
  [nltk_data]   Package punkt is already up-to-date!
  Traceback (most recent call last):
    File "test.py", line 12, in &lt;module&gt;
      frequencies[w] = frequencies[w] + 1 
  KeyError: '\\documentclass'
  </code></pre>
  
  <p>What am I doing wrong? And, how can I print the word and the number of times it occurs in the text file. </p>
  
  <p>You can download <code>book.txt</code>, from <a href="https://www.dropbox.com/s/1q0e555464nia7w/book.txt?dl=1" rel="nofollow">here</a>.</p>