![]() |
Welcome to SIMPL Programming for Python
|
| Course content | Enter chat room | Send email
to mailing list |
Check calendar |
JUST A REMINDER: This course does not have a mailing list. If you need assistance you can email info[ATnospam]icanprogramDOTcom.
In memory of Linda. Worldwide Cancer
sites here.
Canadian Cancer donations here.
Hint:All of these lessons are designed to be worked on off-line. For those of you with dial up Internet access you might find it helpful to print off the page for each lesson and work from the printout. |
The basics |
SIMPL is simultaneously a LGPL'd library, a programming framework and
a toolkit.
SIMPL modules are themselves Linux processes.
SIMPL modules can be written in several languages. Python is one of them.
SIMPL applications consist of two or more interacting SIMPL modules.
SIMPL applications can contain a mixture of SIMPL modules written in
any supported programming language.
Before proceeding, the following assumptions have been made:
The self installing archive discussed in the Course Organization section in the lesson below will allow you to install all the additional tools you will need for these lessons in one simple procedure. Some of you will have been exposed to SIMPL in a previous iCanProgram course. However, it would be advantageous to review the SIMPL toolkit before proceding to the lesson below.
In addition the authors of this course have recently published a book on the SIMPL toolkit. That book includes several examples of using Python in SIMPL applications.
|
|
Programming the SIMPL Way |
What is this course about? |
This course is about extending the messaging power of SIMPL to Python scripts. In this way Python programs can communicate via SIMPL with other network connected programs that also support SIMPL. To date, SIMPL libraries/modules exist for programs written in C, Tcl, Java, and Python running on Linux, Unix, QNX, and MAC OS X platforms.
What is equally important is what this course is not about. It is not a course on how to program in Python. Nevertheless, we will go over certain aspects of Python as they relate directly to the usage of SIMPL.
Why Python? |
We are not going to get into the debate of what languages are better
than others and so on. It suffices to say that each language has its strengths
and weaknesses much like any tool.
We recommend that you read the document called readme.python which is located in the docs directory below the SIMPL root directory. This doc contains a discussion of the reasoning, history and philosophy behind Python SIMPL.
We are using what is known as CPython. That is, Python written in C/C++ as opposed to JPython which has been written in Java. The code that you will use has been run successfully on versions Python1.5 through Python2.5.
For graphics capability, we are using the Tk toolbox via Python's Tkinter module.
What are we going to be doing throughout this course? |
Necessarily, we are going to run and examine some programs. The aim is to show how the following pairs of programs operate:
Lesson #2 - python text-based sender and python text-based receiver,
Python text-based and python graphics-based refer the user interface of the python scripts.
All of the programs have been written for you but you are encouraged to modify them and experiment.
We will be promoting the concept of tokenized message passing in all cases.
There are exactly three different messages that are sent and received throughout all of the lessons. Each message uses a token as an identifier.
The messages are kept the same throughout all of the lessons in order to maintain some continuity. Each message contains different data types in order to demonstrate how these various data types may be used to exchange information between the various senders and receivers.
There is a certain amount of repetition of the programs between the
various lessons. This can be viewed as an example of the versatlility of SIMPL
programs in the sense that any SIMPL program can communicate with any other
SIMPL program on any other supported platform and written in any other
SIMPL supported language.
Course Organization |
All the code you will be using in this course can be downloaded as a tarball from here.
This set of courses is organized in the following hierarchical directory
structure: (Note that /.../ in the directory path is where you have undone
your tar ball.)
| /... /python-simpl-course/src
/.../python-simpl-course/bin |
All of the C source code and Python scripts in the src directory.
All of the C executables will reside in the bin directory.
Necessary System Items |
A Short Overview of Python |
At this point we are going to become acquainted with the parts of the Python language that are necessary for us to accomplish our task of showing how SIMPL may be used in conjunction with Python.
First of all, Python is an interpreted scripting language. This is to say that a Python program is a script written similarly to a shell script.
The script is read by the Python interpreter in the same way that BASH will read a shell script. The Python interpreter is called python and should be found in a directory in your command path, PATH.
To find out where it is, type: "which python" at the command prompt (without the quotes of course). If you get a null result, then you will have to make sure that python has been loaded onto your system and perhaps add its location to your PATH environment variable.
To run a Python script called myProgram.py type: "python myProgram.py" at the command prompt, as always without the quotes.
The interpreter will read the script file called myProgram.py and compile it into a byte code file called myProgram.pyc. It is actually myProgram.pyc that gets run by the interpreter. This is good for many reasons because it allows you to keep your original script from prying eyes and simply release your byte code file in a way that is similar to releasing executable binary code rather than source.
What would a typical myProgram.py file look like? Basically like the
following:
Note:This is not to be run; it is an example only. |
| # we must tell the shell to invoke the interpreter
#! /usr/bin/python """
# blank lines are ignored. single line comments are started with a # just like as in shell scripts # at this point we will import any needed functionality from other python
scripts that come with the distribution
# now we can define one of our own functions. Note that the use of
indents
signal logical code groupings in the same way that C uses brace brackets
# now we put in the body of the code logic
# let's call our defined function
|
A pretty useless script right? To be sure. Nevertheless, this is a basic
layout for a Python program and all of our lesson scripts will follow this
pattern.
Summary |
Let's summarize what you have learned in this lesson.