Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1

Interactive mode has many features that help in the creation and testing of Python scripts. There are
lots of features in IDLE. The following are a few of the most important ones to help you get started in
Python programming:


Menu-driven options and their matching control keys—For example, to open a new IDLE
window, you can click the File menu option and then select New Window from the drop-down
menu. To use the control keys to open a new IDLE window, instead of using the menu, you can
press the Ctrl+N key sequence.
Basic text editor—To type a Python script, you can open up a new window from the main
interactive IDLE window to get access to a very basic text editor. The text editor allows you to
take such actions as cut and paste text using menu-driven selections or control keys.
Code completion—As you type in Python statements, helpful hints appear on the screen, making
recommendations on how to finish the syntax you’ve started.
Syntax checking—When you enter a command and press Enter, the Python interpreter checks
the syntax of your statement and reports any problems immediately. This is much better than
finding out about syntax errors after an entire script is written.
Color coding—The IDLE shell color codes syntax as you type it to help you follow the logic of
your Python statements. Table 3.1 shows the color codes it uses.

TABLE 3.1 IDLE Color Codes

Indentation support—Python requires the use of indentation for some of its constructs. The
IDLE shell recognizes these required indentations and automatically provides them for you.
(For more information on indentation, see Hour 6, “Controlling Your Program.”)
Debugger features—The term debugging refers to removing incorrect syntax or logic from a
program. With IDLE, the Python interpreter’s syntax checking typically finds syntax errors. You
can uncover logic problems by using the IDLE Debugger, which allows you to step through a
program without adding additional Python statements.
Help—Because everyone needs a little help, IDLE provides a nice help facility. You can
access the help facility by selecting the Help menu option on the menu bar of the IDLE window
and clicking IDLE Help in the drop-down menu.

Of course, trying out IDLE’s features yourself will help you better learn to use the IDLE tool. The
following Try It Yourself gives you an opportunity.


Try It Yourself: Explore the Python IDLE Tool
In the following steps, you’ll try out a couple of the IDLE tool’s features. Don’t be
overwhelmed by all the bells and whistles of this tool. Follow these steps to test the
Free download pdf