Advertisement

Python embedding

Started by January 21, 2005 06:18 PM
2 comments, last by GameDev.net 19 years, 7 months ago
hey there. straight to the point: i am trying to get started with Python embedding in my C++ programs, specifically passing and returning values to a Python scripted function which is inside a module: .... pModule = PyImport_Import(pName); .... pDict = PyModule_GetDict(pModule); ... //successfully until now pFunc = PyDict_GetItem(pDict,pFnc); //this doesn't work, i also tried PyDict_GetItemString(..) with char* script is simple: def add(x,y): res = x+y return res so pFnc is PyString_FromString("add") any suggestions?
Well, my first suggestion is to use boost::python if you're embedding Python in a C++ application instead of using the raw Python C API.

Other than that, when you say "this doesn't work" are you saying it doesn't compile, or it returns an error state? If it's an error state, what does PyErr_Print() say?
Advertisement
good point, SiCrane. when i say that is doesn't work i mean that my pFunc variable doesn't get anu value. i was looking into boost::python but decided to go with C/Python API in order to understand it better.
It's strange...

That's what I'm doing :
m_Module = PyImport_Import( modname );
mdict = PyModule_GetDict( m_Module );
ReloadEntryPoint = PyDict_GetItemString(mdict, "Reload");

And to call it :
rslt = PyObject_CallFunction( ReloadEntryPoint , NULL );

And it's just fine...
Are you sure the function you're looking at is in this module ?

This topic is closed to new replies.

Advertisement