Embed extended Python

Mathieu Tremblay mtremblay at golemlabs.com
Fri Sep 13 16:56:32 CEST 2002

   I am quite new to Python and I'd like to embed extended python. 
The problem is that the documentation I can find on the internet is
always related to C standard types and not to C++ objects.

   To extend python I use the really good SWIG tool and everything is
fine.  The problem comes when I try to call a python script that takes
as an argument one of the class that I have defined in C++ through

 C++ class extended to python with SWIG, through the module wheel: 
       printf("I am a wheel");
 Now, let's suppose that the module is successfully exported and can
be used in python.  An example of simple python script would be :
  import wheel
  def thefunction(awheel):

 Calling this function directly from python (supposing we provide the
correct argument) works perfectly.  The problem comes when I want to
call this script from C++.  Maybe It is a stupid question but here it
is: How do you pass an existing CWheel as an argument to the function
from C++??? How do you wrap a CWheel to a PyObject?
 I guess the method would be to use the function
PyObject_CallObject(pFunc, pArgs); the pArgs being a PyTuple where I
can set a PyObject to a position X.  The problem is that all the
examples that I find convert int, char*, long, double etc. to PyObject
with built in python functions but no different/user defined class.
 Anybody can help?

 Thanks a lot,

More information about the Python-list mailing list