HP Caliper Advisor Rule Writer Guide
• Python has full support for classes, but most rule writers will not need to define
their own classes. The analysis object is an instance of a Python class.
• Many built-in and library functions are available. In particular, these modules are
useful to writing Adviser rule functions: re (regular expressions), time (UNIX
time functions), os.path (file and directory name functions), and math (math
functions). See the Python Library Reference for more information.
Python Reserved Words
Reserved words are: and, assert, break, class, continue, def, del, elif, else,
except, exec, finally, for, from, global, if, import, in, is, lambda, not, or,
pass, print, raise, return, try, while, yield.
Python Operators
This section describes the primary Python operators. All of the standard C/C++ operators
exist, with similar semantics, precedence, and built-in functions. Subexpressions can
be grouped with ( ) characters.
• Arithmetic: +, -, *, /, %, //, ~, **
• Comparison: <, <=, >, >=, = =, !=, < >
• Logical: or, and, not
• Bitwise: |, ^, &, <<, >>
• Identity: is, is not
• Membership: in, not in
• Indexing: X[i]
• Slicing: X[i:j]
• Attribute reference: X.attr
• Function call: X(…)
• Tuple: (…)
• List: […]
• Dictionary: {…}
Python Types
Python types include:
• None: the null value.
• Boolean: True, False.
• Numbers: integer, long integer, float, complex.
Numeric literals have C/C++ syntax. Values can be mixed (with implicit conversion)
or explicitly converted (that is, int(expression) ).
• Sequences: strings, lists, tuples.
Strings are immutable (unchangeable) arrays of characters. Lists are mutable
(changeable) arrays of arbitrary values. Tuples are immutable arrays of arbitrary
values. All can be indexed (0 through the number of elements –1) and sliced. Each
66 Python Scripting Language: Overview