Reputation: 1391
I'm writing a python script where I need to open a ".txt" folder and analyse the text in there.
I have saved this ".txt" document in the same folder as my Python script.
But, when I go to open the file; file = open("words.txt",'r')
I get the error: No such file or directory: 'words.txt'
.
I don't understand why this is happening?
Upvotes: 10
Views: 45150
Reputation: 124
It's because the directory of the .py
file you are working with is not the same as the .txt
file's path.
So, you need to mention the path like this:
file = open("C:/User/Desktop/Folder/words.txt", 'r')
Upvotes: -1
Reputation: 479
Hope it helps.
Upvotes: 2
Reputation: 183
Maby it's because your current working directory is different from the directory your files are stored. Try giving the full path to the file
file = open("<full_path>\words.txt",'r')
Upvotes: 12