Page 32 - Programming the Raspberry Pi Getting Started with Python
P. 32
Figure 3-2 Arithmetic in the Python Shell
Editor
The Python Shell is a great place to experiment, but it is not the right place to write a program. Python
programs are kept in files so that you do not have to retype them. A file may contain a long list of
programming language commands, and when you want to run all the commands, what you actually do
is run the file.
The menu bar at the top of IDLE allows us to create a new file. Therefore, select File and then New
Window from the menu bar. Figure 3-3 shows the IDLE Editor in a new window.
Figure 3-3 The IDLE Editor
Type the following two lines of code into IDLE:
You will notice that the editor does not have the >>> prompt. This is because what we write here
will not be executed immediately; instead, it will just be stored in a file until we decide to run it. If
you wanted, you could use nano or some other text editor to write the file, but the IDLE editor
integrates nicely with Python. It also has some knowledge of the Python language and can thus serve
as a memory aid when you are typing out programs.
We need a good place to keep all the Python programs we will be writing, so open the File Browser
from the start menu (its under Accessories). Right-click over the main area and select New and then
Folder from the pop-up menu (see Figure 3-4). Enter the name Python for the folder and press the
RETURN key.