[C++-sig] how to convert C++ objects into python objects?

Qun Cao quncao at alumni.usc.edu
Sat Aug 26 00:26:22 CEST 2006


Hi Everyone,
I have a question regarding type conversion when embedding python in C++.

First, I have created a python module of an C++ class using boost,

#include <classA.cpp>
BOOST_PYTHON_MODULE(PythonTest)
{
	class_<classA>("classA", init<MyString, MyString, MyPoint3>());
}

MyString, MyPoint3 are class types defined in the C++ libraries.
It compiles and generate PythonTest.dll.

Now, I want to call some Python code (object =classA(MyString,
MyString, MyPoint3)  from my main.cpp to create a classA object, how
do I convert
MyString, MyPoint3 variables into Python types?  Also since the python
module does not know anything about C++ objects MyString, MyPoint3; is
it
necessary to extending those classes into Python?

I saw some ways of convert native types such as int, string in
C/Python API, but nothing about generic type conversions.

Thanks for your help!
Qun



More information about the Cplusplus-sig mailing list