Extending Python classes

Steven Feil sfeil at io.com
Sat Dec 22 20:46:54 EST 2001


Question 1: In the document "Extending and Embedding the Python
Interpreter", there is a chapter called "Defining new types". What is
the difference between a "Type" and a class in python?

Question 2: Is there a way to associate an instance of a class with a
C-Language pointer?

If these questions don't make since here is an explanation of what I
have now and what I am trying to acomplish.....

I am working with a project that uses both C and Python. The inner
workings require a lot of calculations. I have written this part in C
in a way that optimize the complex calculation. I would like to import
this program into python and take advantages of OOP.  As it turns out
I have looked into OOP before, but Python is the first OOP language
that I am excited about.


Here is an abstract description of what is happening.

1. A machine is built using instructions contained in a text file.

2. The machine is given a single value from this, it calculates a
   result.

3. Step 2 is repeated as many times as necessary.

4. The machine is decommissioned.

I wrote the C code with this in mind. I have functional equivalents to
a constructor and destructor methods called BuildMachine() and
FreeMachine().  Build allocates a block of memory that contains all
data associated with a OOP instance and returns a pointer.  (In
actuality the root block has pointers to two other blocks of
memory. The root block is always the same size of memory but the size
of the two other blocks are dependent on the amount of data in the
build instructions.)

Currently I am running each active machine as a separate Linux
process.  Each machine is accessed with a pair of fifo's (one for
input and one for output). When I am done with a machine the fifo
closes and the process ends.

Currently, I am experimenting with machines that have no memory of the
previous calculation. Using the current setup it is possible to build
machines that have memory of the previous calculations. In order to be
effective I would need to have to have a reset.  Because I am using
fifo's, it is difficult to send a reset, so I am not using machines
with memory.

I would like to create a python class with with a calculate method and
a reset method (in addition to the constructor and destructor
methods).

========================================================================
 Steven Feil               | Gram-pa, back at the turn of the      .~.  
 Programmer/Developer      | century, why did people use an        /V\  
 sfeil at io.com              | operating system, when they were not // \\ 
                           | allowed to see the source code?      (X_X) 
========================================================================



More information about the Python-list mailing list