Why am I getting a FileNotFoundError

0 votes

I am working on a program that read a file and searches for a word then prints how many times that word is found in the file. When I  type in "test.rtf" 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'

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

Can someone help me with this?

May 24, 2022 in Python by Kichu
• 19,040 points
747 views