[C++-sig] looking up functions

Alan Baljeu alanbaljeu at yahoo.com
Thu Nov 13 16:08:53 CET 2008


Hans Meine wrote:
>I don't see the problem.  AFAICS, "ask for a function by name" is "ask python 
>[i.e. callout to python] for a function [which is an object that I can safe 
>when I want to call it repeatedly] by name".  Which part could be simpler?

As best I could figure, I needed to write Python code, execute a script file, get that code to call a C function that I register, in order to have that function.  At least the tutorial implied that was the way.

Gustavo gives a better approach.  Thanks.

 Alan Baljeu



________________________________
From: Gustavo Carneiro <gjcarneiro at gmail.com>
To: Development of Python/C++ integration <cplusplus-sig at python.org>
Sent: Thursday, November 13, 2008 9:48:43 AM
Subject: Re: [C++-sig] looking up functions




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



      __________________________________________________________________
Get a sneak peak at messages with a handy reading pane with All new Yahoo! Mail: http://ca.promos.yahoo.com/newmail/overview2/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20081113/12bf0f9c/attachment.htm>


More information about the Cplusplus-sig mailing list