Skip to main content
gamedev.net
🔒 Locked

Python embedding

Started by pnroach Jan 21, 2005 at 6:18 PM 2 replies 1.5k views
Original Post
pnroach
pnroach
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?
SiCrane
SiCrane
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?
pnroach
pnroach
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.