1

I have installed python 2.7.10 in my windows 7 32 bit system. I have created a small script test.py and saved it in the folder D:\python27. Now when I execute test.py from windows cmd it runs fine. But when I run python from the command line and then execute the same command test.py I get the error:

File "<stdin>",line 1, in<module>NameError:name 'test' is not defined.
0

2 Answers 2

2

This is not how you execute a python script. Instead of starting the python interpreter and then typing

test.py

you have to type

python test.py

directly into the command line.

What you did is starting the python interpreter. This is for directly typing and executing python commands in the shell/cmd.

Sign up to request clarification or add additional context in comments.

1 Comment

I you think this answer fits your question, do me a favor and mark it as the solution. Thanks!
0

You can not execute a python script from python interpreter as from the terminal,

from terminal it is:

python test.py

In your python command line:

You can only import it as import test

or if you have args in it you can use os

import os

os.system("test.py") 

Comments

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.