Question

Hello, I would greatly appreciate it if anyone could help me. I saved a text file...

Hello,

I would greatly appreciate it if anyone could help me.

I saved a text file in the C drive of my computer. I need to use open the text file to do my homework. But when I used the Python 3.7 to open the file, I got error message: NO SUCH FILE OR DIRECTORY.

What should I do to open the file using the Python.

Many thanks for your help.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

There might be the possibility that the file you are trying to open is actually missing. Or you are making a mistake in writing the file path. Check these two things first. Below is a working example of reading a text file from the C drive on my computer using Python 3.7. To resolve these issues you can copy and paste the location of your file directly from the file explorer. You may also try to create a new file and check whether it is opened or not, there might be if there are some security issues involved.

Note: You have to duplicate the backslashes in the file path as:

C:\\Users\\beejb\\Desktop\\Instruction Manual.txt

Or else it will throw a unicode error.

CODE:

# the file handler
fh =open("C:\\Users\\beejb\\Desktop\\Instruction Manual.txt")
#a simple for loop to print the lines of the given text file
for line in fh:
    print(line)


OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Hello, I would greatly appreciate it if anyone could help me. I saved a text file...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT