26.4. Python Interpreter

On a UNIX system, the Python interpreter is called an Integrated DeveLopment Environment (IDLE) but is usually thought to be named after a character in the Monty Python comedy troop for which Python itself was named. IDLE is usually installed as /usr/local/bin/python or /usr/bin/python. If its location is in your PATH, you can start it by typing the following command: python.

On a Windows system, the Python IDE is GUI-based and is called PythonWin. PythonWin is usually installed in the same directory as Python. The executable is called pythonwin.exe.

Python is available for Mac, too. That project is called MacPython, and it contains the Mac version of IDLE.

Whichever operating system you choose, you will find that, in interactive mode, the interpreter will display a prompt of >>>. This prompt allows you to type in your Python commands. If any of these commands are not built in, you must first import the module that contains that command, like this:

>>> import re

To exit the Python interpreter, type an end-of-file character (Control+D on UNIX, Control+Z on Windows) at the primary prompt. The interpreter will exit with a zero exit status.

You can also invoke a Python script directly by making the first line of the script look like this,

#!/usr/local/bin/python

with the path representing the path to the Python interpreter. Although the preceding hard-coded method works, on UNIX systems the preferred method is to use the env command, which will look for the ...

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.