Reputation: 11
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.
Upvotes: 1
Views: 225
Reputation: 2807
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")
Upvotes: 0
Reputation: 1244
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.
Upvotes: 2