Running Python Scripts

From Staffwiki

(Difference between revisions)
Jump to: navigation, search
m (How to Execute)
Line 44: Line 44:
# Create a text file with the extension "txt" from MS Word.
# 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.
# Place the file in PythonScripts (or another directory of your choice) located in My Documents.
 +
# Click the start button in Window's lower left corner
 +
# Choose run and click it
 +
# Enter cmd in the Open: dialog input box
 +
# Click OK
# Attach to (on library machines a now configured): C:\Documents and Settings\csu_employee\My Documents\PythonScripts
# Attach to (on library machines a now configured): C:\Documents and Settings\csu_employee\My Documents\PythonScripts
 +
## Type cd My Documents
 +
## Type cd PythonScripts
# Type C:\python26\python myfile.txt myfile.csv
# Type C:\python26\python myfile.txt myfile.csv
# Examine the comma separated value (csv) file for accuracy
# Examine the comma separated value (csv) file for accuracy
# Import the csv file to MS Excel
# Import the csv file to MS Excel

Revision as of 17:06, 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. 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. Attach to (on library machines a 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. Import the csv file to MS Excel
Personal tools