How do I save this?

Discussion in 'Mac Programming' started by Dmac77, Aug 4, 2008.

  1. Dmac77 macrumors 68020

    Dmac77

    Joined:
    Jan 2, 2008
    Location:
    Michigan
    #1
    Hi,

    I'm working out of a book to learn python, and I can't for the life of me figure out how to get textedit to save a file as a .py file. does anyone know how I can do this?

    Thanks,

    Don
     
  2. itickings macrumors 6502a

    itickings

    Joined:
    Apr 14, 2007
    #2
    If you want to use TextEdit for Python, you need to make sure the file is saved as plain text.

    I would recommend Xcode instead of TextEdit. Xcode would give you syntax highlighting (makes code easier to read) and it would automatically save your file in the correct format.
     
  3. Dmac77 thread starter macrumors 68020

    Dmac77

    Joined:
    Jan 2, 2008
    Location:
    Michigan
    #3
    Thank you! I'll try Xcode, I didn't think that I could use it for python, because the book said to use a text editor.

    Thanks!

    Don
     
  4. itickings macrumors 6502a

    itickings

    Joined:
    Apr 14, 2007
    #4
    The book said text editor to keep things simple. Environments such as Xcode can do a lot of additional things too.

    Just fire up Xcode, select "File", "New File" and "Python Tool". That way you will be using Xcode as a glorified text editor, just what the book is written for. :)

    Good luck!
     
  5. Dmac77 thread starter macrumors 68020

    Dmac77

    Joined:
    Jan 2, 2008
    Location:
    Michigan
    #5
    Ok, I'm using Xcode now. But I have ran into another problem:(. I'm trying to get python to run the file, by entering it's name into the terminal, but everytime i try, it returns with an error, and yes I'm starting python in the terminal.
    The book says to enter this into terminal after launching python in the terminal: % python spam.py

    The book is written from a windows prospective (referring to the the shell command as Command Prompt, but I know that terminal is the shell prompt for OS X), is the "%" sign referring to entering the full path of the file?

    Sorry for being so helpless!

    Don
     
  6. itickings macrumors 6502a

    itickings

    Joined:
    Apr 14, 2007
    #6
    No worries, getting started is almost always the hardest part.

    To run your program, enter any of the following in the Terminal:
    Code:
    python [path to file]/spam.py
    or
    Code:
    cd [path to file]
    python spam.py
    For example, if you've saved the file spam.py in the Documents folder in your home directory

    Code:
    cd ~/Documents
    python spam.py
    If it still won't run, post the error you're getting.
     
  7. Dmac77 thread starter macrumors 68020

    Dmac77

    Joined:
    Jan 2, 2008
    Location:
    Michigan
    #7
    ^^^

    Thanks! It worked!!! It's really intimidating, trying to learn a programing language, but luckily I have this great community to help me:)

    Don
     

Share This Page