Calling Python functions from C from strings 
Author Message
 Calling Python functions from C from strings

I can easily call a python function when I am handed a reference to the
function as a PyObject*, but how do I call a Python function (from C) when
all I have is its name? eg:

def mysub:
    print 'hello world'
    ...

And all I have is the string "mysub", how do I call this function? In Perl I
would use perl_call_argv().

I need to use a string, rather than a PyObject* because portability to other
languages is an issue, and a storing a string reference to a function seems
like the best way.



Wed, 28 Aug 2002 03:00:00 GMT  
 Calling Python functions from C from strings

Quote:

> And all I have is the string "mysub", how do I call this function?

Try the following:

m = PyImport...("__main__"); /* not sure exact name of function -- see
                                docs*/

Use the abstract protocol to get m.mysub

Now you have a PyObject *, so we solved your problem.

can-anyone-else-tell-i'm-a-mathematician-ly y'rs, Z.
--

http://www.oreilly.com/news/prescod_0300.html



Wed, 28 Aug 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. python strings ( function func_doc strings )

2. Last expression vrbl (was: python strings ( function func_doc strings ))

3. python strings ( function func_doc strings )

4. VC++ calling fortran function and fortran function calling a c++ function

5. How to find out name of calling function from called function

6. Does any language allow calling strings as functions?

7. Does any language allow calling strings as functions?

8. string function called by C challenge

9. call of non-function (type string) error

10. Call a function in DLL with string arguments?

11. Turn string into function call

12. Calling functions from functions from functions ...

 

 
Powered by phpBB® Forum Software