Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




The IDLE Development Environment

There are a number of possible integrated development environments (IDE) for Python. Python includes the IDLE tool, which we'll emphasize. Additionally, you can purchase a number of IDE's that support Python. In Other Tools we'll look at tools that you can use to create a IDE-like toolset.

Starting and Stopping

Starting and stopping IDLE varies with your operating system. Generally, all of the variations are nearly identical, and differ only in minor details.

Windows. There are several ways to start IDLE in Windows. You can use IDLE (Python GUI) from the Python2.5 menu on the Start menu.

You can also run IDLE from the command prompt. This requires two configuration settings in Windows.

  • Assure that C:\Python25\Lib\idlelib on your system PATH. This directory contains IDLE.BAT.

  • Assure that .pyw files are associated with C:\Python25\pythonw.exe. In order suppress creation of a console window for a GUI application, Windows offers pythonw.exe.

You can quit IDLE by using the Quit menu item under the File menu.

Mac OS. In the Mac OS, if you've done an upgrade, you may find the IDLE program in the Python 2.5 folder in your Applications folder. You can double-click this icon to run IDLE.

You can always find IDLE in the directory /System/Library/Frameworks/Python.framework/Versions/Current/bin. Generally, this is on your PATH, and you can type the command idle in a Terminal window to start IDLE. The idle2.5 icon is a document, not an applicaction, and can't easily be put into your Dock.

You can create your own Applescript icon to run the IDLE shell script. This requires a single line of Applescript:

do shell script "/System/Library/Frameworks/Python.framework/Versions/Current/bin/idle" 

When you run IDLE from the icon, you'll notice that two windows are opened: a Python Shell window and a Console window. The Console window isn't used for much.

When you run IDLE from the Terminal window, no console window is opened. The Terminal window is the Python console.

You can quit IDLE by using the Quit menu item under the File menu. You can also quit by using the Quit Idle menu item under the Idle menu.

Since the Macintosh keyboard has a command key, ⌘, as well as a control key, ctrl , there are two keyboard mappings for IDLE. You can use the Configure IDLE... item under the Options menu to select any of the built-in Key Sets. Selecting the IDLE Classic Mac settings may be more comfortable for Mac OS users.

GNU/Linux. We'll avoid the GNOME and KDE subtleties. Instead, we'll focus on running IDLE from the Terminal tool. Since the file path is rather long, you'll want to edit your .profile (or .bash_profile) to include the following alias definition.

alias idle='env python /usr/lib/python2.5/idlelib/ &'

This allows you to run IDLE by entering the command idle in a Terminal window.

You can quit IDLE by using the Exit menu item under the File menu.

Basic IDLE Operations

Initially, you'll see the following greeting from IDLE.

Python 2.5.1 (r251:54863, Oct  5 2007, 21:08:09) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "copyright", "credits" or "license()" for more information.

    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
IDLE 1.2.1      

The personal firewall notification is a reminder that IDLE uses Internetworking Protocols (IP) as part of its debugger. If you have a software firewall on you development computer, and the firewall software complains, you can allow the connection.

IDLE has a simple and relatively standard text editor, which does Python syntax highlighting. It also has a Python Shell window which manages an interactive Python session. You will see that the Python Shell window has a Shell and a Debug menu.

When you use the New menu item in the File menu, you'll see a file window, which has a slightly different menu bar. A file window has name which is a file name (or untitled ), and two unique menus, a Run and a Format menu.

Generally, you'll use IDLE in two ways:

  • You'll enter Python statements in the Python Shell window.

  • You'll create files, and run those module files using the Run Module item in the Run menu. This option is usually F5 .

The Shell Window

The Python Shell window in IDLE presents a >>> prompt. At this prompt, you can enter Python expressions or statements for evaluation. This window has a complete command history, so you can use the up arrow to select a previous statement and make changes.

You can refer back to Command-Line Interaction; those interactions will look and behave the same in IDLE as they do on the command line.

The Shell Window is essentially the command-line interface wrapped in a scrolling window. The IDLE interface, however, provides a consistent working environment, which is independent of each operating system's command-line interface.

The Shell and Debug menus provides functions you'll use when developing larger programs. For our first steps with Python, we won't need either of these menus. We'll talk briefly about the functions, but can't really make use of them until we've learned more of the language.

The Shell Menu. The Shell menu is used to restart the Python interpreter, or scroll back through the shell's log to locate the most recent restart. This is important when you are developing a module that is used as a library. When you change that module, you need to reset the shell so that the previous version is forgotten and the new version can be imported into a fresh, empty interpreter.

Generally, being able to work interactively is the best way to develop working programs. It encourages you to create tidy, simple-looking components which you can exercise directly.

The Debug Menu. The Debug menu provides some handy tools for watching how Python executes a program.

  • The Go to File/Line item is used to locate the source file where an exception was raised. You click on the exception message which contains the file name and select the Go to File/Line menu item, and IDLE will open the file and highlight the selected line.

  • The Debugger item opens an interactive debugger window that allows you to step through the executing Python program.

  • The Stack Viewer item opens a window that displays the current Python stack. This shows the arguments and working variables in the Python interpereter. The stack is organized into local and global namespaces, a conceot we need to delve into in Chapter 6, Variables, Assignment and Input .

  • The Auto-open Stack Viewer option will open the Stack Viewer automatically when a program raises an unhandled exception. How exceptions are raised and handled is a concept we'll delve into in Chapter 17, Exceptions .

The File Windows

Each file window in IDLE is a simple text editor with two additional menus. The Format menu has a series of items for fairly common source text manipulations. The formatting operations include indenting, commenting, handling tabs and formatting text paragraphs.

The Run menu makes it easy to execute the file you are editing.

  • The Python Shell menu item brings up the Python Shell window.

  • The Check Module item checks the syntax for your file. If there are any errors, IDLE will highlight the offending line so you can make changes. Additionally, this option will check for inconsistent use of tabs and spaces for indentation.

  • The Run Module, F5 , runs the entire file. You'll see the output in the Python Shell window.

  Published under the terms of the Open Publication License Design by Interspire