15-105 SPRING 2009 [CORTINA]

Using Python - Windows

INSTALLING PYTHON

If you are using Windows, you will need to download a Python interpreter for your computer.

Go to http://www.python.org/download/ and download the Python 2.6.1 Windows Installer (Windows binary - does not include source).

Run the installer. Select a location to install Python 2.6.1 (e.g. C:\Python26). You can use the default installation settings.

CREATING A PYTHON DIRECTORY

After you install Python, you can use the Python folder (e.g. C:\Python26) as your Python directory where you can store your Python programs.

EDITING PYTHON PROGRAMS

Use Notepad or another text editor to create your Python program and store it in the same folder as the Python interpreter.

IMPORTANT NOTE: When you save using Notepad, be sure that "Save type as:" says "All files", NOT "Text Documents". Then save your file with an extension of .py (e.g. gcd.py). If you set "Save type as:" to "Text Documents", Notepad will save your file with an extra .txt extension (so you get gcd.py.txt) and the Python interpreter won't see it as a Python program.

RUNNING PYTHON

INTERACTIVE MODE
Go to the folder that contains your Python installation and double-click on the Python interpreter application. It is named python, not pythonw. You can now enter python commands one at a time in interactive mode and get immediate feedback.

COMMAND LINE MODE (TO RUN A COMPLETE PROGRAM)
Alernatively, you can run python programs as follows.

1. Start the Python interpreter (double-click on it), and type the command "import " filename, without the .py. For example:

import gcd

You should see your program run.

2. Using the Start menu, go to All Programs → Accessories → Command Prompt. This will start up a Windows terminal window. Navigate to your Python folder. For example:

cd C:\Python26\

Then you can run your program by typing:

python filename.py

For example: python gcd.py