I want to be able to analyze a local txt file I have using NLTK. By analyze, I mean use NLTK capabilities such as tokenizing, sentiment analysis etc.
I have a local file in my Python directory named 'example.txt'.
import nltk
from nltk.tokenize import sent_tokenize, word_tokenize
with open ('example.txt', 'r') as f:
for line in f:
f_contents = f.readlines()
print(word_tokenize(f_contents))
I am trying to print 'f_contents' in tokenized format. 'F_contents' in this case should be the text within 'example.txt'.
Any help would be appreciated.