1

I am running a basic Python file on Windows XP from IDLE.

The file name is assignment1.py. The file content is:

import sys
var = 5

but when I run it, it gives the error:

Command: python assignment1.py
SyntaxError: invalid syntax

Then I tried another thing which also gave an error:

Command: which python
SyntaxError: invalid syntax

Not sure if the installation is wrong or something.

I am able to run the print command successfully:

>>> print "I am working fine"
I am working fine

Not sure of the issue. Request help.

pradyunsg
  • 18,287
  • 11
  • 43
  • 96
Bonson
  • 1,418
  • 4
  • 18
  • 38

1 Answers1

1

It looks like what you are entering as the "command" is being interpreted as Python code. I mean, python assignment1.py is interpreted as Python code. The result is as expected:

$ python -c 'python assignment1.py'
  File "<string>", line 1
    python assignment1.py
                     ^
SyntaxError: invalid syntax

You need to run the file in the correct way, probably via the IDLE menu or by pressing F5. You can check these questions for details:

Community
  • 1
  • 1
Lev Levitsky
  • 63,701
  • 20
  • 147
  • 175