[C++-sig] looking up functions

Gustavo Carneiro gjcarneiro at gmail.com
Thu Nov 13 15:48:43 CET 2008

2008/11/13 Alan Baljeu <alanbaljeu at yahoo.com>

> I'm reading the Python extension tutorial, and I cannot believe the
> embedding section.  It tells me the only way to call a python function is to
> callout to python to pass back a function object which I then save so I can
> call it when I need to.  This seems ridiculous.  Surely there is a way to
> obtain Python function objects without going through that!  Does somebody
> have a way to ask for a function by name?

PyObject *function_object = PyObject_GetAttrString (PyModule_Import
("modulename"), "function_name");

Leaks a module object reference, but you get the idea...

Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20081113/cdd70142/attachment.htm>

More information about the Cplusplus-sig mailing list