Running commands from Powershell

J82

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.

Hasan Ramezani

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

Just put file name in Quotation Mark:

f = open('ex15_sample.txt')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related