I tried running a simple python file from the command line. I created a python file called script0.py with the following content
print 2**2
I get a syntax error.
>>> python script0.py
File "<stdin>", line 1
python script0.py
^
SyntaxError: invalid syntax
>>>
What is that? My first try with python has been really bad and the book of Mark Lutz is not helping. I use Python 2.7.
Thanks
1 Answer 1
You are running that code from inside the python interpreter. If your terminal is showing a leading >>> it means your inside python already, in there you can either type print 2**2 directly, or exit and call python script0.py
My guess is that you inadvertently entered the python interpreter and thought you were still at the command prompt. Type exit() and try again.
demo
5 Comments
C:\Python27\python.exe C:\Users\Username\Desktop\my_python_script.py changing the routes to those on your system
python script0.pydoesn't go in an interactive Python session; it goes in the shell, a.k.a. command prompt.