Super Beginner Python Help

Discussion in 'Mac Programming' started by DairyJogger, Feb 24, 2011.

  1. DairyJogger macrumors newbie

    Joined:
    Feb 24, 2011
    #1
    Okay, I have decided that I would like to learn some programming, and have taken to MIT's OpenCourseware lectures/curriculum to aid me in this process. I have no previous programming experience.

    I saw this "Hello, world!" program and decided to give a test-run just to make sure everything was working properly, my IDLE search path was in order, etc.

    I attempted to run this simple program, yet I keep getting a syntax error, and I literally have no idea why. I will take you step by step through what I did, because I feel quite dumb for not understanding this simple procedure.

    FYI, I am running Python 2.7, which I DL off the Python site on Mac OS X 10.6. I am also referencing this: http://en.wikibooks.org/wiki/Python_Programming/Creating_Python_programs

    So I opened IDLE, and typed:

    print "Hello, world!"

    i saved this as a hello.py and then proceeded to follow all the directions that the wiki gave in Terminal. yet, in Terminal, I keep getting this error:

    [​IMG]

    Note* I tried print("Hello, World!") also, same thing.

    Can someone please tell me what the heck I am doing wrong? Am I completely misguided here?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Sounds like you saved the entire contents of IDLE's window to hello.py, which isn't what you want.

    I'd suggest not using IDLE since Terminal already provides what you need.

    Open up hello.py in TextEdit and make sure the contents of the file are only
    Code:
    print "Hello, world!"
    and then try again.
     
  3. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #3
    I have no idea, it might be related to the fact that you use a different version than the system supplied. Any specific reason you did this? I mean why make things more complicated than they need to.

    Anyway, try copy paste this into terminal.

    Code:
    echo "print 'hello'" > p.py ; python p.py
    It will leave a file behind named p.py. Does it work to use the interactive interpreter? ie just type python at the command line?
     

Share This Page