HP Caliper Advisor Rule Writer Guide

A Python Scripting Language: Overview
Python is a general-purpose, object-oriented language with many features that most
rule writers do not need. This appendix gives a brief summary of the features of Python
that are relevant to writing rules.
NOTE: The latest version of Python is 2.4.1. HP Caliper currently uses version 2.3.4.
When writing rules, be careful not to use newer Python features that are unsupported
by HP Caliper.
Python Documentation
See the Python Web site for tutorials and full documentation:
http://www.python.org
These documents are particularly useful:
Python Tutorial by Guido van Rossum
Python Library Reference by Guido van Rossum
Python Reference Manual by Guido van Rossum
Quick reference: Python Pocket Reference, 3rd Edition, by Mark Lutz, ISBN
0-596-00940-2
Reference book: Python Essential Reference, 2nd Edition, by David M. Beazley, ISBN
0-735-71091-0
Python Concepts
Some basic concepts are:
Names are case-sensitive and made of uppercase and lowercase letters, digits, and
underscores. The first character should be a letter. Leading underscores control
scope and should be avoided.
Objects are not explicitly declared but are defined by first assignment. An object’s
type is dynamic, based on the value it currently contains and can be changed by
assigning a different value to it.
Functions do not need to be defined physically before they are referenced.
Local objects used in a function are discarded when the function returns. Python
uses a reference-count system of automatic garbage collection.
Each statement is terminated by a newline or ; character. It is preferable to put
only one statement on each line. Long statements can span several lines by using
the \ character at the end of all but the last line.
Indentation is used to group statements within functions, if constructs, and loops
instead of { } characters.
Extra white space (spaces, tabs, newlines) can be used to improve readability but
statement indentation must be maintained.
Comments begin with the # character and the rest of the line is ignored.
Python Documentation 65