Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Tried to open a .txt file using Python and got a 'FileNotFoundError'

FileNotFoundError: [Errno 2] No such file or directory: 'en_US.twitter.txt'

with open("en_US.twitter.txt", "r") as f:
    data = f.read()
print("Data type:", type(data))
print("Number of letters:", len(data))


What I have tried:

Tried to open the .txt file saved on my desktop.
Posted
Updated 5-Dec-22 19:00pm

1 solution

Read the error message, it tells you everything you need to know:
FileNotFoundError: [Errno 2] No such file or directory: 'en_US.twitter.txt'

The file does not exists in the current folder. Possibly it exists in a different folder, or possibly it has a different name and / or extension - we can't tell.

Find the file, and add a path to it. We can't help you with that!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900