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

Nat Linden nat at lindenlab.com
Wed Jun 6 12:50:36 CEST 2012


On Wed, Jun 6, 2012 at 5:09 AM, Nagaraju <srirangamnagaraju at gmail.com> wrote:

> I wrote a wrapper class in the same file as BOOST_PYTHON_MODULE(hello).
>
> Now when I compiled this DLL, I get Test.DLL.

Hmm, the module thinks its name is "hello", but it's in Test.DLL?
Maybe it should be hello.pyd?

The .pyd is to designate it as a Python extension. Python stopped
importing plain .dlls along about Python 2.5.

> Now from Python, I wrote a script to load this Test.DLL.

As 'import Test' or as 'import hello'?

> How can I access add, sub and other functions in my Python script?

You said you wrote a wrapper class, and that the add, sub etc. are
methods on that class?

Let's say your wrapper class is called Wrapper.

import hello
obj = hello.Wrapper()  # instantiate

-- or, equivalently --

from hello import Wrapper
obj = Wrapper()

-- then, either way --

print obj.add(something, something_else)


More information about the Cplusplus-sig mailing list