user7319905
user7319905

Reputation:

error while running python script

I am a learner of python.

i created one simple python script named as test.py file location(/Users/AnbeswaranK/Desktop/python/test.py.

when i try to run the the script i am getting below error.

>>> python test.py
SyntaxError: invalid syntax
>>> 

>>> python /Users/AnbeswaranK/Desktop/python/test.py
SyntaxError: invalid syntax
>>> 

I have tried with location url and without but unable to run.

can any one help me to understand, what i have to do

Thanks in advance

Upvotes: 0

Views: 7899

Answers (3)

Andrew White
Andrew White

Reputation: 1

Based on what I am seeing, primarily with ">>>python test.py" this tells me that the reason why you have an error is because you wrote it in the IDLE Shell and saved it. I just ran into this problem and figured it out.

So what you are going to want to do is this:

  1. Open "File" and go to "New File"
  2. Write you code in the new file.
  3. Save your file in your desktop (you don't have to save it here, it can be anywhere).
  4. Open your terminal and go to that path ( I like to go to the File Explorer, go to where my file is located and type in "cmd" so that the command prompt can open with path already there).
  5. Type "python [yourfilename].py" and BOOM, you should be good to go.

Upvotes: 0

Enrico
Enrico

Reputation: 1

Check test.py and make sure you have only python command. I had the same as I saved from IDLE with all not necessary text coming by default with IDLE. I.e.:

  1. move test.py on your Desktop, erase everything inside it and replace with a simple command like : print('Hallo')
  2. open Terminal , move to Desktop with cd /Users/AnbeswaranK/Desktop
  3. write python test.py

When you want to create a new python file just click on "File-->New File" of the IDLE :-)

Let me know if this works

Upvotes: 0

user7759009
user7759009

Reputation:

  1. Open your command prompt.

  2. Navigate to the folder where your test.py is located.

  3. type and enter: python test.py

Upvotes: 0

Related Questions