Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Dmac77

macrumors 68020
Original poster
Jan 2, 2008
2,165
3
Michigan
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
 

itickings

macrumors 6502a
Apr 14, 2007
947
185
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.
 

Dmac77

macrumors 68020
Original poster
Jan 2, 2008
2,165
3
Michigan
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.

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
 

itickings

macrumors 6502a
Apr 14, 2007
947
185
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.

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!
 

Dmac77

macrumors 68020
Original poster
Jan 2, 2008
2,165
3
Michigan
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
 

itickings

macrumors 6502a
Apr 14, 2007
947
185
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

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.
 

Dmac77

macrumors 68020
Original poster
Jan 2, 2008
2,165
3
Michigan
^^^

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

Don
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.