Calling a Python function with parameters
Hello, I've now managed to load a python module using boost::python::exec_file() I can extract variables and run functions from C++ too. But I am stumped on how to pass parameters from C++ to a python function. Not much use without that! I'm using boost::python::extract<std::string>(global["pyFunc"]) to run the function, where the python module may be: ##------------------------ def func1(): return "hello from python" pyFunc = func1() ##----------------------------------- The docs don't seem to elaborate on how to add parameters. There is plenty on calling C++ functions from python...... What I want to do is something like this: // C++ answer = extract<std::string>(global["pyFunc(""hi"", ""there"" )"] ## python def pyFunc( str1, str2 ): return str1+str2 Thanks for putting up with a newbie! Simon http://www.simonpickles.com --- http://www.squirtualreality.com _________________________________________________________________ Get a preview of Live Earth, the hottest event this summer - only on MSN http://liveearth.msn.com?source=msntaglineliveearthhm
On 6/8/07, Simon Pickles <sipickles@hotmail.com> wrote:
Hello,
I've now managed to load a python module using boost::python::exec_file()
I can extract variables and run functions from C++ too.
But I am stumped on how to pass parameters from C++ to a python function. Not much use without that!
I'm using boost::python::extract<std::string>(global["pyFunc"]) to run the function, where the python module may be:
##------------------------ def func1(): return "hello from python"
pyFunc = func1() ##-----------------------------------
The docs don't seem to elaborate on how to add parameters. There is plenty on calling C++ functions from python......
What I want to do is something like this:
// C++ answer = extract<std::string>(global["pyFunc(""hi"", ""there"" )"]
## python def pyFunc( str1, str2 ): return str1+str2
Thanks for putting up with a newbie!
I guess this is what your are looking for: http://boost.org/libs/python/doc/v2/call.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/
participants (2)
-
Roman Yakovenko -
Simon Pickles