I'm trying to open a bunch of files in a directory, remove some words from those files and write the output to a file in the same directory. I'm having problems when trying to write to the output file. There isn't anything being written to the file. How can I fix this?
Here is my code:
path = 'C:/Users/User/Desktop/mini_mouse' output = 'C:/Users/User/Desktop/filter_mini_mouse/mouse' for root, dir, files in os.walk(path): for file in files: os.chdir(path) with open(file, 'r') as f, open('NLTK-stop-word-list', 'r') as f2: mouse_file = f.read().split() # reads file and splits it into a list stopwords = f2.read().split() x = (' '.join(i for i in mouse_file if i.lower() not in (x.lower() for x in stopwords))) with open(output, 'w') as output_file: output_file.write(x)
with open(output, 'w') as output_file:C:/Users/User/Desktop/filter_mini_mouse/mousebut in your open statement, you're writing to a file namedout.