1

I am a beginner in Python and am learning via online tutorials. On Study Drill #6 for example 15 on this page, I'm trying to open up the 'ex15_sample.txt' file that I have created and exists.

This is what it says to do:

Start 'python' to start the Python shell, and use 'open' from the prompt just like in this program. Notice how you can open files and run 'read' on them from within 'python'?

In the command prompt, I entered python to start the Python shell and have tried typing in the following, which threw me an error:

open(ex15_sample.txt)

The error I get is:

Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'ex15_sample' is not defined

ex15_sample.txt is a file that exists in the same folder. How am I supposed to use open or any other command from the prompt? I am running Python 2.7.8 on Powershell, by the way.

1 Answer 1

2

The first argument of open is a string containing the filename.

Just put the file name in quotation marks:

f = open('ex15_sample.txt')
Sign up to request clarification or add additional context in comments.

2 Comments

Ok, I did that and it didn't open but it threw me this: <open file 'ex15_sample.txt', mode 'r' at 0x0000000001F54150>
that means file is open , you can put it in a variable an work with it. please read this link. check my edit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.