I am new to python programming. Right now i am doing natural language processing on text files. The problem is that i have around 200 text files so its very difficult to load each file individually and apply the same method.
here's my program:
import nltk
from nltk.collocations import *
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
from nltk import FreqDist
with open("c:/users/user/desktop/datascience/sotu/stopwords.txt", 'r') as sww:
sw = sww.read()
**with open("c:/users/user/desktop/datascience/sotu/a41.txt", 'r') as a411:
a41 = a411.read()
a41c=word_tokenize(str(a41))
a41c = [w for w in a41c if not w in sw]**
so i want to apply this method on multiple files. Is there a way i can load all the files in one step and apply the same method. I tried this but it did not work:
import os
import glob
import nltk
from nltk.collocations import *
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
from nltk import FreqDist
with open("c:/users/user/desktop/datascience/sotu/stopwords.txt", 'r') as sww:
sw = sww.read()
for filename in glob.glob(os.path.join("c:/users/user/desktop/DataScience/sotu/",'*.txt')):
filename=word_tokenize(str(filename))
filename = [w for w in filename if not w in sw]
xqc=FreqDist(filename)
please help.