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

Bing Chen BC at prism.co.nz
Wed Feb 23 23:28:38 EST 2000


I pass a object from c++ to Python as follow:
  PyObject *pargs = Py_BuildValue("Oli",m_curr,field.first,field.second);
  PyObject *pdict, *pval;
  pdict = PyDict_New();
  PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());

  PyDict_SetItemString(pdict, "Y", pargs);   /* dict['Y'] = pargs   */
  PyRun_String("from BaseModule import *",  file_input, pdict, pdict);
  PyRun_String("X = BaseModelLink(Y)", file_input, pdict, pdict);
the "m_curr" is an instance of class in my application, when I  run some
method in the Python program as follow:
 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?

Thank you guys in advance!
BC






More information about the Python-list mailing list