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?
asked May 8, 2011 at 7:02
Jonathan Livni
108k112 gold badges278 silver badges367 bronze badges
2 Answers 2
Create your own type and fill the tp_*attr members appropriately.
answered May 8, 2011 at 7:09
Ignacio Vazquez-Abrams
804k160 gold badges1.4k silver badges1.4k bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Jonathan Livni
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 Livni
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++?
Ignacio Vazquez-Abrams
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.IIRC Boost.Python http://www.boost.org/doc/libs/1_54_0/libs/python/doc/index.html will do a lot of the heavy lifting for you here.
answered Jul 8, 2013 at 20:49
Maxim Khesin
6171 gold badge6 silver badges10 bronze badges
Comments
Explore related questions
See similar questions with these tags.
lang-cpp