[C++-sig] Accessing Class Member Function from Python

Nagaraju srirangamnagaraju at gmail.com
Wed Jun 6 15:38:50 CEST 2012


Hi Nat,

Thank you very much for the reply.
I tried making the target as ".pyd" and I am able to import it in Python
script.

Thanks again.

Regards,
Raju.
On Wed, Jun 6, 2012 at 6:57 PM, Nat Linden <nat at lindenlab.com> wrote:

> On Wed, Jun 6, 2012 at 6:57 AM, Nagaraju <srirangamnagaraju at gmail.com>
> wrote:
>
> > Thank you very much for your reply. I am sorry if I did not explain
> > something clearly.
> >
> > I am doing as below after implementing the MyClass in the same file:
> >
> > BOOST_PYTHON_MODULE(hello){
> > ...
> > }
> >
> > I am using CDLL from ctypes to load this Test.DLL. Say
> > planet = CDLL("Test.DLL").
> >
> > Now I want to create an object of MyClass and call add function. How can
> I
> > do this?
>
> I think you're mixing two different tactics here.
>
> You can use ctypes to load a plain DLL that publishes extern "C"
> functions, and call those functions. But I don't believe it supports
> the notion of a Python class defined in that DLL.
>
> Or you can use Boost.Python to prepare a special DLL that Python will
> recognize as an extension module. Such modules can be loaded with
> 'import'. In this case you don't use ctypes because the module
> contents describe themselves for the Python runtime to know how to use
> them directly, classes and methods and functions and data.
> Boost.Python is a succinct way to provide such a description.
>
> But it's my belief that a DLL containing the description compiled from
> BOOST_PYTHON_MODULE(hello) must be named "hello.pyd" for the Python
> interpreter to successfully import it.
>
> Once you're able to import hello, you should be able to instantiate
> hello.MyClass() and proceed from there.
>  _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20120606/777bd92a/attachment-0001.html>


More information about the Cplusplus-sig mailing list