RE: [C++-sig] How do I wrap a C++ object to a PyObject*
From: Ralf W. Grosse-Kunstleve [mailto:rwgk@yahoo.com]
--- David Abrahams <dave@boost-consulting.com> wrote:
"Bjorn Pettersen" <BPettersen@NAREX.com> writes:
I've looked through the documentation but haven't found anything obvious...
Let's see. You have a wrapped C++ class somewhere? If so, you can write in __main__:
import some_boost_python_module x = some_boost_python_module.some_class(some_arg)
But this is trivially explained in the docs, so you must mean something else...
I believe he wants to do this from C++. I don't know what __main__ is, but I am guessing that his problem is solved by using a construct like this:
scope().attr("key") = value;
which I believe is just a shorthand for
scope().attr("key") = object(value);
This sets an attribute in the importing module. value can be any object that is convertible from C++ to Python, including but not limited to instances of a user-defined classes X with a corresponding class_<X> statement.
Cool. Thanks! -- bjorn
participants (1)
-
Bjorn Pettersen