Can I run a c++ object in Python program?

Olaf Delgado delgado at olaf.de
Thu Feb 24 04:25:04 EST 2000


In article <892c2s$maj$1 at news.ihug.co.nz>,
	"Bing Chen" <BC at prism.co.nz> writes:
> I pass a object from c++ to Python as follow:
>   PyObject *pargs = Py_BuildValue("Oli",m_curr,field.first,field.second);

[...]

>  def BaseModelLink(pargs):
>      base = pargs[0]
>      vid = pargs[1]
>      unit = pargs[2]
>      return base.get_lit(vid,unit)
>  it crash.
> How can I make the object work in the pyhton program?

It is not enough to pass the address of a C++ object. You have to make
each of it's methods available individually to Python, i.e. write a
wrapper function for each of them and make it known to the
interpreter. The online docs describe how this is down.

There is also a program called Swig (see www.swig.org) which can do
that almost automatically for you.

Olaf

-- 
  ////
  Olaf  Delgado Friedrichs, Bielefeld, Germany
  `='   --- http://www.mathematik.uni-bielefeld.de/~delgado ---



More information about the Python-list mailing list