Problem using exported C++ functions to python
Hi, I have the following type of functions in a class say "MyClass", which I have exported to python. 1) func1(long *plong) 2) func2(TempClass **pptempclass) (where TempClass is some other class) Now, I exported these using the following: .def("func1", &MyClass::func1) .def("func2", &MyClass::func2) and it compiled well. But now when I try to use them in a python script, I have no clue as to how I create and pass: 1) a long pointer as argument to func1 2) a double pointer to TempClass as argument to func2 How do I achieve this behaviour? 1) Do I have to wrap the above functions> If yes, then how? How will they be used in python then? OR 2) I can still use the same functions in python but then how to create (instantiate and initialize) the above pointers in python? Thanks, Mayank
mayankg@iiitb.ac.in writes: Please bring Boost.Python questions to the C++-sig: http://www.boost.org/more/mailing_lists/cplussig
Hi, I have the following type of functions in a class say "MyClass", which I have exported to python.
1) func1(long *plong) 2) func2(TempClass **pptempclass) (where TempClass is some other class)
Now, I exported these using the following:
.def("func1", &MyClass::func1) .def("func2", &MyClass::func2)
and it compiled well.
But now when I try to use them in a python script, I have no clue as to how I create and pass: 1) a long pointer as argument to func1 2) a double pointer to TempClass as argument to func2
How do I achieve this behaviour?
You don't. Python ints and floats are immutable, so you can't pass them to a C++ function that could change them.
1) Do I have to wrap the above functions> If yes, then how? How will they be used in python then?
The latter is the question I would ask you: how would you like/expect to be able to use them from Python? You have to come up with an appropriate interface (e.g. "in Python func1 accepts and returns an int"); once you've done that, it's usually easy to wrap the function. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
participants (2)
-
David Abrahams
-
mayankg@iiitb.ac.in