- with open(book.txt_file.path) as f:
- m = re_text(f.read())
- if not m:
- print self.style.ERROR("Unknown text format: %s" % book.slug)
- skipped += 1
- continue
-
- processed += 1
- last_word = ''
- text = unicode(m.group(1), 'utf-8').lower()
- for letter in text:
- mydict = lesmianator.setdefault(last_word, {})
- myval = mydict.setdefault(letter, 0)
- mydict[letter] += 1
- last_word = last_word[-2:] + letter
+ f = open(book.txt_file.path)
+ m = re_text(f.read())
+ if not m:
+ print self.style.ERROR("Unknown text format: %s" % book.slug)
+ skipped += 1
+ continue
+
+ processed += 1
+ last_word = ''
+ text = unicode(m.group(1), 'utf-8').lower()
+ for letter in text:
+ mydict = lesmianator.setdefault(last_word, {})
+ myval = mydict.setdefault(letter, 0)
+ mydict[letter] += 1
+ last_word = last_word[-2:] + letter
+ f.close()