[C++-sig] Returning values to Python in C++ reference arguments

Nikolay Mladenov nikolay.mladenov at gmail.com
Mon May 25 20:16:49 CEST 2015


You have to do something like that

using namespace boost::python;

BOOST_PYTHON_MODULE(my_module)
{
    struct wrapper{
       static tuple bar(Foo & f){
           double a, b;
           f.bar(a,b);
           return make_tuple(a,b);
       }
    };
    class_<Foo>("Foo", init<>())
        .def("bar", &wrapper::bar)
    ;
}

and in python it will be:

>>> a,b = Foo().bar()

On Mon, May 25, 2015 at 5:39 AM, Trigve Siver via Cplusplus-sig <
cplusplus-sig at python.org> wrote:

>
>
> ----- Original Message -----
> > From: Jason Addison <jraddison at gmail.com>
> > To: cplusplus-sig at python.org
> > Cc:
> > Sent: Saturday, May 23, 2015 6:05 PM
> > Subject: [C++-sig] Returning values to Python in C++ reference arguments
> >
> > How can results be returned in function arguments?
> >
>
>
> I don't think that you can return arguments by reference/pointers in
> python. You could theoretically pass a mutable sequence (list) and push the
> objects there.
>
> But the common approach is to return tuple.
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> https://mail.python.org/mailman/listinfo/cplusplus-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20150525/bcf9cbb9/attachment.html>


More information about the Cplusplus-sig mailing list