user1625016
user1625016

Reputation: 41

I do not understand the reason for this syntax error

I am a trying to learn python 2 and I do not have any background in computer language I am using the tutorial "ByeofPython". The exercise ask us to enter this into the editor (text wrangler)

#!/usr/bin/python
#Filename : helloworld.py
print "Hello World'

And the save it as helloworld.py. I did this and saved it onto my desktop in a folder called python exercises.

The tutorial then asks us to:

Run this program by opening a shell (Linux terminal or DOS prompt) and entering the command python helloworld.py. If you are using IDLE, use the menu Edit -> Run Script or the keyboard shortcut Ctrl-F5. The output is as shown below.

$ python helloworld.py
Hello World

However when I go to terminal and enter python helloworld.py I get this

python helloworld.py
                    ^
SyntaxError: invalid syntax

Can someone tell me where I went wrong? I feel that I entered everything correctly. I am using a Mac and running python 2.6

Upvotes: 4

Views: 374

Answers (2)

Lethargy
Lethargy

Reputation: 1889

You may be typing into the python interpreter, and the command you're entering isn't valid Python. To exit this mode, you could either press CTRL-D (end of file), or CTRL-C (interrupt program).

(I'm not sure if these key sequences are the same on windows)

If you run the command python without the name of a script file after it, it will start reading user input as if it was a python program.

Upvotes: 1

Joe Day
Joe Day

Reputation: 7264

You are getting a SyntaxError because your quotes do not match.

Your print line should be:

print "Hello World"

not

print "Hello World'

Upvotes: 4

Related Questions