Last updated: Saturday 2nd July 2011, 7:21 PT, AD

 

 

www.annedawson.net

 

How to run the Python interpreter

 

Introduction

 

After installing the Python software, the Python interpreter is ready to run single Python commands like:

 

print "Hello World!"

 

The CSCI120A Course Notes and the CSCI165A Course Notes web pages contain instructions for the use of various editors which allow you to store several Python statements in one file to be executed in sequence by the Python interpreter.

 

 

Running the Python interpreter

 

Please note: the screen shots shown are generated from a computer running the Windows 98 operating system. If you have another version of Windows the screens may look slightly different, but the procedures you should follow are the same.

 

You can run the Python interpreter in a number of ways:

 

Running Python - Method 1

 

On your desktop, click on the Start button, then click on Run .

 

 

 

Assuming you installed the Python software to the folder:

 

C:\Python23

 

In the Run window, enter the following text in the text box, then click on the OK button.

 

C:\Python23\python.exe

 

 

 

 

 

You will then see Python running in an MSDOS window (DOS shell):

 

 

 

 

 

You will see a few lines of information followed by the Python prompt >>>. A prompt is simply the location where instructions are typed in (at the shell command line).

 

After typing in a Python statement at the prompt, you must press the Enter key (also known as the Return key) on your keyboard.

 

At the >>> prompt, try typing in the following simple Python statement:

 

print "Hello World!" (then press the Enter key).

 

Python responds by printing the text "Hello World!" (without the quotes).

 

If you've got this far, you know that Python has been installed correctly!

 

 

 

 

 

 

 

Notice that after Python interprets and executes your command, the prompt returns ready for the next command (Python statement). When running in this manner the Python interpreter is said to be in the interactive mode, and will continue in this mode indefinitely until you issue the command to quit.

 

To exit from the Python interpreter you must hold down the Ctrl keyboard key and press the Z key at the same time (Ctrl-Z). (Different operating systems may require a different key sequence, e.g. Ctrl-C).

 

 

 

 

 

 

 

 

Running Python - Method 2

 

On your desktop, click on the Start button, then click on Programs , then Python 2.3.4 , then select Python (command line) from the list of options.

 

 

 

 

 

 

 

 

 

 

 

Notice that the Python interpreter is running in exactly the same DOS shell as shown in Method 1 above. You may follow the same instructions for using the interpreter as described for Method 1.

 

 

 

 

Running Python - Method 3

 

 

In the third method of running the python interpreter, you execute the interpreter by typing its file name at an MSDOS shell command line. From the desktop, click on the Start button, then click on Programs , then MS-DOS Prompt . (In other versions of Windows, the MS-DOS prompt may have an alternative name, eg DOS Shell, Command shell, etc.)

 

 

 

 

 

 

 

 

 

Please note, other operating systems may default to a different folder than C:\WINDOWS. Notice that the prompt for MS-DOS is a single right arrow symbol >. The prompt for the Python interpreter is >>>.

 

 

Then type in the following text at the MS-DOS prompt, and press the Enter key to run the Python interpreter:

 

 

c:\python23\python.exe

 

 

 

 

 

 

 

The screen above shows the Python interpreter running in interactive mode. See Running Python - Method 1 for an explanation of interactive mode and instructions on the use of the Python interpreter with single Python commands. As explained earlier, to exit from the Python interpreter you must hold down the Ctrl keyboard key and press the Z key at the same time. (Operating systems other than Windows may require a different key sequence, e.g. Ctrl-C).

 

If you run Python from an MS-DOS Prompt shell, exiting from Python returns you to the MS-DOS Prompt shell. To close the DOS shell and return to Windows, you must exit the MS-DOS Prompt environment by typing exit at the command prompt, then press the Enter key. An example of this is shown in the screen below.