5

I am a programming (and Python) novice. I am unable to run any python script in command prompt of my WinXP 64-bit laptop. I assigned the path and confirmed it by typing set path. I have Python32. I get the following message:

>>>python hello.py

File <”stdin”> , Line1
  Python hello.py
             ^
SyntaxError: Invalid syntax

Following is the script I tried:

#!/usr/bin/python
message = "Hello, world!"
print(message)

6 Answers 6

6

You should type this

python hello.py

at the dos/cmd prompt, not inside the Python Interpreter

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

1 Comment

I started learning python (on a windows machine) today and spend my first 30 mins searching for this answer. Thank you. Other tutorials etc. just expect a noob to know this, as if this would be some inherited information hardcoded into everyone's brain at the time of birth. Ha Ha Ha. Thanks again, also like your name :)
5

Do it like this:

Go the directory(python32 in my example) and type python hello.py.

If you only type python in cmd then it'll launch the python interpreter after that python hello.py will return Syntax error.

enter image description here

Comments

1

Another way of doing it inside the interpreter is by just importing the name of the module without the .py so for example, in your case:

>>>import hello

would return

Hello, World!

Comments

0

You are typing the command inside the Python shell, do it from the DOS prompt.

I.e.,

 C:\somepath\> python hello.py

since you already have the python executable on the path (the number 1 problem usually when things don't work), you should be set to go.

1 Comment

@info-nowise ha ha .. yes, it's not quite higgs-boson, but Python definitely is cool :)
0

python is the command you use to run the script so you run it in the shell. In Windows, that would be the command prompt (Run > "cmd").

Comments

0

You're inside the python interpreter not the windows command line.

To open the windows command line go to

Start -> All Programs -> Accessories -> Command Prompt

Then you will need to change into the directory where you have stored hello.py. If it was on your desktop you would do:

cd Desktop

and then after that you could do:

python hello.py

and it would work.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.