[C++-sig] using extract with embedded boost::python
seefeld at sympatico.ca
Mon Jun 4 15:44:39 CEST 2007
Simon Pickles wrote:
> Thanks Stefan.
> On consulting libs/python/tests/exec.cpp I got the extract to work, with
> simple data types, like int and std::string.
> How can I do the same for a function. I tried:
> // C++
> python::dict global;
> python::object result = python::exec_file("myPython.py", global, global)l
> python::object greet = global["greet"];
> std::string message = python::extract<std::string>(greet());
> // MYPYTHON.PY
> def greet(self):
> return "hello, world!"
> This gives an error. Its the example from the documentation.
What error ?
I'm not exactly sure about the above: greet() returns a new object, and
extract<std::string> returns something (a proxy ?) which is implicitly convertible
to a std::string. Is it possible that the lifetime of the object to be extracted
from is slightly shorter than that of the proxy ? David ?
Does it make a difference if you store the result of greet() in a local object
and extract from that ?
> Then, can I also pass parameters?
pass to what ? The function call ? That's all covered in the tutorial / manual.
> As for PyErr_Fetch, since I am not using a console application (win32),
> I don't know what to do with PyErr_Fetch or PyErr_Print! Sorry, not big
> on console apps!
I don't quite understand the relation to "console app". If your platform doesn't
have support for stdout / stderr, you surely have other means to display text.
...ich hab' noch einen Koffer in Berlin...
More information about the Cplusplus-sig