The simplest way to run programs for this course is use the Python system installed on Sandbox.
You can also edit a file with your favorite editor (pico, vi and emacs are available), and run your file with the python command.
You will often want to use the Unix shell redirects to read from or write to a file.
Installing On Linux
Python is standard equipment on most Linux distributions; if you have Linux, you almost certainly have Python. You can run Python programs on Linux using the python filename form as shown above. However, Linux, in common with other Unix-like systems, allows you run scripts by specifying the interpreter on the first line and marking the the file executable. This allows you place the script anywhere on your command path and run it as an ordinary command by just typing the file name. To do this, you must:
Where /usr/bin/python is the location of your python interpreter, and filename is whatever you call your python file. Then, if filename is on your command path, filename becomes a command which just runs the python program.
Python comes with a small GUI development environment called Idle. It's not really needed on Linux, but can be useful. You can run it with a command like:
Installing on Windows
To install Python on windows, download the official distribution from http://www.python.org/download/. The latest one as of this writing is 2.5.1. The Windows package is an MSI file that installs quite painlessly.
After installation is complete, you should have a Python entry in your start menu, with several submenu selections. The "python command line" submenu item will bring up a window into which you can interactively type python expressions. The "IDLE" selection will run the IDLE environment which allows you edit and run Python programs. You will find IDLE very useful on Windows. When IDLE comes up, you will see an interactive window where you can type Python expressions, much like the python command line selection. To open an editor window, use File/New Window. When you have entered a Python program and saved it, you can run it by selecting Run, then Run Module from the IDLE editor window. Your program will be run in the interactive window that originally came up when you started IDLE.
The Windows install binds the .py file extension to python, but this alone is often fairly useless for the text-based programs we'll write in this class. When you click on a python file, it opens a window, runs, and disappears. If you look quickly enough, you can just see it flash. If the program takes input, the window will stay up while you enter, then disappear just after the results are printed. IDLE solves this problem since the execution window stays open after you program finishes.
To follow some of the things we do in class, you will want to be able to run Python from a command window. To do this, you will need to add Python to the Windows execution path. The command path is just a list of directories where the system will look when trying to find a command, something like:
These adjustments will allow you run Python files from a command prompt with python filename. The Unix style input and output redirection will also work in this environment.
Note: On Unix, interactive Python sessions are terminated with control-D. On Windows, use control-Z. These are keyboard EOF characters for the respective systems.