By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,087 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

Calling a python function from C++

P: n/a
Let's say I have a python function do some math like the following:

def doMath(self):
self.val = self.val + 1
How can I call this python function from C++? Assuming I have some sort
of Python wrapper around my C++ codes.

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
la********@gmail.com wrote:
Let's say I have a python function do some math like the following:

def doMath(self):
self.val = self.val + 1
How can I call this python function from C++? Assuming I have some sort
of Python wrapper around my C++ codes.


See the "Embedding and Extending" tutorial. In short, you write

resultObj = PyObject_CallMethod(selfObj, "doMath", "");
if (resultObj == NULL)
return NULL;
Py_DECREF(resultObj); // resultObj should be Py_None

How you get hold of self depends on your application.

Regards,
Martin
Jul 19 '05 #2

P: n/a
djw
la********@gmail.com wrote:
Let's say I have a python function do some math like the following:

def doMath(self):
self.val = self.val + 1
How can I call this python function from C++? Assuming I have some sort
of Python wrapper around my C++ codes.


Elmer?

http://elmer.sourceforge.net/
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.