Why am I getting a FileNotFoundError?

I’m trying to write a simple program to read a file and search for a word then print how many times that word is found in the file. Every time I type in “test.rtf” (which is the name of my document) I get this error:

Traceback (most recent call last):
  File "/Users/AshleyStallings/Documents/School Work/Computer Programming/Side Projects/How many? (Python).py", line 9, in <module>
    fileScan= open(fileName, 'r')  #Opens file
FileNotFoundError: [Errno 2] No such file or directory: 'test.rtf'

In class last semester, I remember my professor saying you have to save the file in a specific place? I’m not sure if he really said that though, but I’m running apple OSx if that helps.

Here’s the important part of my code:

fileName= input("Please enter the name of the file you'd like to use.")
fileScan= open(fileName, 'r')  #Opens file

Leave a Comment