[C++-sig] Calling a Python function with parameters

Roman Yakovenko roman.yakovenko at gmail.com
Sat Jun 9 20:01:29 CEST 2007


On 6/8/07, Simon Pickles <sipickles at 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/



More information about the Cplusplus-sig mailing list