Chapter 2. Users Guide

In the last chapter you've seen how to use the default scripts distributed with CapiSuite. But the main goal in developing CapiSuite was not to provide a perfect ready-to-use application. I intended to develop a tool where you can write your own applications very easyly. I'll show you how to do this in the next sections.

As I thought about the scripting language I wanted to integrate into CapiSuite, my first idea was to develop an own, simple one. But as more as I looked into it, the more I found that a general purpose language will be much more helpful than re-inventing every wheel that I would need. So I looked for some easy to integrate (and to learn) language. The one I liked most was Python - and it also had a nice documentation about embedding, so I chose it and I'm still happy about that decision. :-)

So the first thing you'll have to do is to learn Python. Don't be afraid - it was developed as a beginners language and Guido (Guido van Rossum, the inventor of Python) has done very well in my opinion.

In the next few sections, I'll give you a short introduction to the features of Python you most probably will need for CapiSuite. As this shouldn't be a manual about Python or a tutorial in computer programming, I assume you're already familiar with the basic concepts of todays wide-spread procedural and object-oriented languages.

If not, I would advise you to get and read a book for learning Python - there are many available in different languages. The Python home page on http://www.python.org has also nice and comprehensive manuals and tutorials available for free.

Python supports most features you know from other common languages. Here's the syntax of the basic operations shown in a Python session. A Python session is another fine feature of its interpreter: just start it by typing python in a shell and you'll get a prompt:

gernot@linux:~> python
Python 2.2.1 (#1, Sep 10 2002, 17:49:17)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>>

As you can see, the Python prompt is >>>. If you enter commands that span multiple lines, Python shows a second prompt: ...

>>> if (1==2):
...     print "Now THAT's interesting!"
...

Ok, now let's go on:

>>> # comments start with # at the begin of a line
>>> # now the usual first steps
>>> print "hello world"
hello world
>>> # variables
>>> a=5 # no separate declarations necessary
>>> b=a*2
>>> print b
10
>>> b='hello'
>>> print b,'world'
hello world
>>> # python is very powerful in handling sequences
>>> a=(1,2,3) # defines a tuple (not changeable!)
>>> print a
(1, 2, 3)
>>> a[1]=2  # this must fail
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: object doesn't support item assignment
>>> a=[1,2,3] # defines a list (changeable)
>>> a[1]=7
>>> print a
[1, 7, 3]
>>> # control structures
>>> if (b=='hello'):
...     print "b is hello"
... else:
...     print "????"
...
b is hello
>>> # the for statement can iterate over sequences
>>> for i in a:
...     print i
...
1
7
3
>>> # replace positions 1 to 3 (without 3) with 0
>>> a[1:3]=[0]
>>> a
[1, 0]
>>> # a[-i] is the i-the element counted from the back
>>> a[-1]=7; a[-2]=8
>>> a
[8, 7]