Python Syntax Error

Discussion in 'Mac Programming' started by WMBenham, Sep 8, 2010.

  1. macrumors newbie

    Joined:
    Jul 20, 2010
    #1
    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
    Code:
    print "Hello, World"
    I get an invalid syntax error. Am I missing something here?
     
  2. macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #2
    Functions need brackets around them.

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

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    That works for me in Python 2.6.1. The need for parens on print is something that has changed in Python.
     
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    The following works for me. Mac OS 10.6.3.

    First, launch Terminal.app. Enter this command:
    Code:
    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:
    Code:
    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.
     

Share This Page