Now that you've downloaded and installed Python, it's time to continue your studies. You can program in Python using any editor/development environment your like. But, a quite capable IDE comes with Python, Python IDLE. Here, you'll find out what IDLE does and how you can integrate it into your development workflow.
On Windows and on the Mac, the installer for Python automatically installs idle. To launch in Windows, tap the Windows key and type idle. On Mac, use Cmd+Space and type idle.
With Linux, you may or may not have to install it separately, depending on how you install it and the package source. Once you've got it, just type idle to run it.
Figure 1: The IDLE opening screen
The Interactive Interpreter
As you can see, this is not an editor where you begin typing your application. This is the Python Interactive Interpreter, a shell where you can enter commands and immediately see the results.
For example, type this line and press Enter.
>>> a = 42
Now, type this and press Enter.
The value you assigned to a is displayed. This interactive Python shell is a quick and easy way to try out new code or to hammer out an unfamiliar syntax, whenever you need to.
You'll often see example code shown, as the previous two lines, with the >>> preceding. This suggests that you type in these examples with the Interactive Interpreter.
To open the editor, open the File menu and choose New File. A very simple looking editor appears.
Figure 2: The editor's window
Don't let the simple window fool you, though. The editor provides a host of features to make your development life easier. Among them are:
- Multi-windows text editor with search/replace within and across files
- Syntax highlighting
- Autocompletion and autoindent
- Multiple undo
- Class browser and class browser
- Integrated debugger
- Persistent breakpoints, stepping
- Stack viewing and local/global namespace viewing
We haven't yet talked about Python's commands or syntax, but go ahead and type the following program into the editor window.
theirName = raw_input('Kind sir, what may I call you?\n') print 'Good day, %s. Good day indeed!' % theirName
Now, open the File menu and choose Save As…. Save the file to your hard drive and name it greeting.py.
Figure 3: The greeting.py code, colored to assist you
As you can see, the editor automatically colored different parts of your program in different ways. This is syntax highlighting and it makes reading code much easier—especially when there's a lot of it.
To run your program, open the Run menu and choose Run Module (note the shortcut key so you can use that later, rather than navigating the menus each time). A new window will open where the application runs. Oblige the good man and type your name, and press Enter.
Figure 4: Entering your name and getting a response
Works like a charm. Go back to the editor and add this line after the others.
print('Rare weather today, aye?')
Now, run the program again. You may be prompted to save the modified program.
Figure 5: Notice the name change and the new response
The updated program runs in the same shell window, but it's easy to distinguish one run from the next.
You've discovered the IDLE editor, seen some of its features, and walked through the simple procedure for entering running and modifying programs. Congratulations—you're now ready to dive into the Python language!