Running Python Scripts

From Staffwiki

Jump to: navigation, search


Install the Python Language Interpreter

Obtain the Windows self extracting installation file from Interpreter Downloads, choosing the Python 2.6.4 Windows binary

When Windows prompts, Run the interpreter taking all defaults. This will leave an executable file "python.exe" in C:\python26\python.exe.

You will use this from the command line if you are running a program rather than developing a script. The IDLE platform (or a full featured editor such as EMACS) is a valuable structured development environment.

Example: Running a Previously Developed Script with Data

In this example, a script named "" has already been created. The script reads a text file with label:value data and rotates these data to produce a spreadsheet. The labels are column labels and these are as many rows as sets of unique labels. Complete data are assumed, though some attempt is made to allow for missing data.

Example Input File

Author: Emily Bronte
Title: Wuthering Heights
Publisher: Random House
Author: Samuel Clemens
Title: Tom Sawyer
Publisher: Knopf

Example Output File (from running the script)

Author Title Publisher
Emily Bronte Wuthering Heights Random House
Samuel Clemens Tom Sawyer Knopf

How to Execute

The simplest way to run this script is by using direct file names in the CMD box window. This is Windows Command Line (DOS like) execution. The script can also be run via IDLE, but that is not part of this How To.

  1. Create a text file with the extension "txt" from MS Word.
  2. Place the file in PythonScripts (or another directory of your choice) located in My Documents.
  3. Click the start button in Window's lower left corner
  4. Choose run and click it
  5. Enter cmd in the Open: dialog input box
  6. Click OK
  7. Use the command line to attach to (on library machines as now configured): C:\Documents and Settings\csu_employee\My Documents\PythonScripts
    1. Type cd My Documents
    2. Type cd PythonScripts
  8. Type C:\python26\python myfile.txt myfile.csv
  9. Examine the comma separated value (csv) file for accuracy
  10. Make changes as needed to the txt file; rerun and recheck
  11. Import the csv file to MS Excel
Personal tools