Running Python Scripts

From Staffwiki

(Difference between revisions)
Jump to: navigation, search
(Example Input File)
Line 37: Line 37:
|}
|}
 +
 +
=== 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.
 +
 +
# Create a text file with the extension "txt" from MS Word.
 +
# Place the file in PythonScripts (or another directory of your choice) located in My Documents.
 +
# Attach to (on library machines a now configured): C:\Documents and Settings\csu_employee\My Documents\PythonScripts
 +
# Type C:\python26\python myfile.txt myfile.csv
 +
# Examine the comma separated value (csv) file for accuracy
 +
# Import the csv file to MS Excel

Revision as of 17:02, 12 November 2009

Contents

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 "word2xls.py" 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. Attach to (on library machines a now configured): C:\Documents and Settings\csu_employee\My Documents\PythonScripts
  4. Type C:\python26\python myfile.txt myfile.csv
  5. Examine the comma separated value (csv) file for accuracy
  6. Import the csv file to MS Excel
Personal tools