In order to understand what happens when you're programming, you need to have a basic understanding of how a program gets executed on a computer. The computer itself is assembled from pieces of hardware, including a processor that can execute instructions and do arithmetic, a place to store data such as a hard drive, and various other pieces such as computer monitor, a keyboard, a card for connecting to a network, and so on.
To deal with all these pieces, every computer runs some kind of operating system, such as Microsoft Windows, Linux, or Mac OS X. An operating system, or OS, is a program; what makes it special is that it's the only program on the computer that's allowed direct access to the hardware. When any other program on the computer wants to draw on the screen, find out what key was just pressed on the keyboard, or fetch data from the hard drive, it sends a request to the OS (see Figure 2.1, on the following page).
This may seem a roundabout way of doing things, but it means that only the people writing the OS have to worry about the differences between one network card and another. Everyone else—everyone analyzing scientific data or creating 3D virtual chat rooms—only has to
Figure 2.1: Talking to the operating system learn their way around the OS, and their programs will then run on thousands of different kinds of hardware.
Twenty-five years ago, that's how most programmers worked. Today, though, it's common to add another layer between the programmer and the computer's hardware. When you write a program in Python, Java, or Visual Basic, it doesn't run directly on top of the OS. Instead, another program, called an interpreter or virtual machine, takes your program and runs it for you, translating your commands into a language the OS understands. It's a lot easier, more secure, and more portable across operating systems than writing programs directly on top of the OS.
But an interpreter alone isn't enough; it needs some way to interact with the world. One way to do this is to run a text-oriented program called a shell that reads commands from the keyboard, does what they ask, and shows their output as text, all in one window. Shells exist for various programming languages as well as for interacting with the OS; we will be exploring Python in this chapter using a Python shell.
The more modern way to interact with Python is to use an integrated development environment, or IDE. This is a full-blown graphical inter -face with menus and windows, much like a web browser, word processor, or drawing program.
Our favorite IDE for student-sized programs is the free Wing 101, a "lite" version of the professional tool.1
1. See http://www.wingware.com for details.
Another fine IDE is IDLE, which comes bundled with Python. We prefer Wing 101 because it was designed specifically for beginning programmers, but IDLE is a capable development environment.
The Wing 101 interface is shown in Figure 2.3, on the next page. The top part is the editing pane where we will write Python programs; the bottom half, labeled as Python Shell, is where we will experiment with snippets of Python programs. We'll use the top pane more when we get to Chapter 4, Modules, on page 50; for now we'll stick to the shell.
The >>> part is called a prompt, because it prompts us to type something.
Was this article helpful?