1

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

2 Answers 2

2

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

answered May 8, 2011 at 7:09
Sign up to request clarification or add additional context in comments.

3 Comments

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?
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++?
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.
1

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.