Python documentation gives a nice introduction to Extending and Embedding Python with C\C++. However, in many cases there's a need to transfer complex data structures between the languages.

What would be the best way to achieve this?

link|improve this question

78% accept rate
feedback

1 Answer

up vote 1 down vote accepted

Create your own type and fill the tp_*attr members appropriately.

link|improve this answer
Do I really need to create a new type just to transfer a struct from C\C++ to Python and back? Isn't there a way to map it to a dictionary for instance? – Jonathan May 10 '11 at 11:18
Also - If I do create a new type - would I need to convert the data between it and the C\C++ data structure in C\C++? – Jonathan May 10 '11 at 11:20
You don't actually "transfer" anything between C/C++ and Python; a type instance holds the struct as a member, and the tp_*attr functions convert data back and forth. – Ignacio Vazquez-Abrams May 10 '11 at 11:35
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.