PDA

View Full Version : Python Syntax Error




WMBenham
Sep 8, 2010, 07:06 PM
Hey all,

I just started learning Python and am working in IDLE. My very first tutorial suggested I try the basic "Hello, World" test and when I input print "Hello, World" I get an invalid syntax error. Am I missing something here?



MorphingDragon
Sep 8, 2010, 08:10 PM
Hey all,

I just started learning Python and am working in IDLE. My very first tutorial suggested I try the basic "Hello, World" test and when I input print "Hello, World" I get an invalid syntax error. Am I missing something here?

Functions need brackets around them.

print("My life is average currently")

What python tutorial are you using? I might be able to get you/point to something better and more up-to-date (PM me)

angelwatt
Sep 8, 2010, 08:53 PM
That works for me in Python 2.6.1. The need for parens on print is something that has changed in Python (http://diveintopython3.org/porting-code-to-python-3-with-2to3.html).

chown33
Sep 8, 2010, 08:56 PM
The following works for me. Mac OS 10.6.3.

First, launch Terminal.app. Enter this command:
python -m idlelib.idle

A few seconds elapse, then a separate Python Shell window appears with the copyright notice, firewall message, and finally the >>> prompt. Example from an IDLE tutorial:
http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html
except mine says IDLE 2.6.1.

I then type in:
print "Hello, world"
and hit Return. It prints what I typed in.

This isn't the only way to run Python's IDLE, but it does work here.


I suggest copying the contents of the IDLE window that shows the command and resulting error message, and pasting it into a post. It's as simple as cmd-A (Select All), cmd-C (Copy) in the IDLE window, then paste it into a reply post and surround it with CODE tags.


It would be a good idea to identify exactly which OS version and Python version you're using, along with the IDLE version. Also, if you're using IDLE.app rather than the command-line I entered, or some other way of starting IDLE, that should also be identified.