469,646 Members | 1,739 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

Calling a python function from C++

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
2 1522
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
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.

Similar topics

reply views Thread by Natsu Mizutani | last post: by
2 posts views Thread by Satish Chimakurthi | last post: by
1 post views Thread by Stephen Kellett | last post: by
4 posts views Thread by Edwin Gomez | last post: by
varuns
reply views Thread by varuns | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.