Creating Programs with a Text Editor
The Python interactive interpreter performs your instructions as soon as you type them.
Often, it is better to compose a multiline program using a text editor, then ask Python
to run the whole program at once. Using IDLE, you can do this by going to the File
menu and opening a new window. Try this now, and enter the following one-line
program:
print ‘Monty Python’
Save this program in a file called monty.py, then go to the Run menu and select the
command Run Module. (We’ll learn what modules are shortly.) The result in the main
IDLE window should look like this:
================================ RESTART ================================
Monty Python
You can also type from monty import * and it will do the same thing.
From now on, you have a choice of using the interactive interpreter or a text editor to
create your programs. It is often convenient to test your ideas using the interpreter,
revising a line of code until it does what you expect. Once you’re ready, you can paste
the code (minus any >>> or … prompts) into the text editor, continue to expand it,
and finally save the program in a file so that you don’t have to type it in again later.
Give the file a short but descriptive name, using all lowercase letters and separating
words with underscore, and using the .py filename extension, e.g., monty_python.py.
