Create a instance of Python Class in C++

Nicodemus nicodemus at icablenet.com.br
Sun Aug 25 07:54:57 CEST 2002


Is boost python v2 out yet? Last time I checked, it was in planning phase...

Farewell,
Nicodemus.

----- Original Message -----
From: "David Abrahams" <david.abrahams at rcn.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Thursday, August 22, 2002 7:06 PM
Subject: Re: Create a instance of Python Class in C++?


> "Gerhard Häring" <gerhard.haering at gmx.de> wrote in message
> news:slrnama98b.i6.gerhard.haering at lilith.my-fqdn.de...
> > Arivazhagan wrote in comp.lang.python:
> > > Hi
> > >
> > > Do any one know how to use a class defined in python in C++? Is it
> > > possible?
> >
> > Call it with PyObject_CallObject. Get access to the class using
> > PyObject_GetAttr, once you have its module object.
>
>
> Or, in Boost.Python v2,
>
>     double use(object some_class)
>     {
>         // Make an instance of some_class
>         object inst = some_class(3, "hello");
>
>         // set an attribute
>         inst.attr("x") = 2;
>
>         // call a method: inst.method_name(42)
>         object result = instance.attr("method_name")(42);
>
>         // Get the C++ value out
>         return extract<double>(result);
>     }
>
> HTH,
> Dave
>
> -----------------------------------------------------------
>            David Abrahams * Boost Consulting
> dave at boost-consulting.com * http://www.boost-consulting.com
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list