python data types in c++ code

Stefan Behnel stefan_ml at behnel.de
Sun Mar 6 12:57:12 EST 2011


Arthur Mc Coy, 06.03.2011 17:40:
> Ok, I managed to work with c++ data types in python and can store
> serialize c++ objects to store in json.
>
> Now the task is backward. I wrote a c++ code to get the list of
> objects using again python interface. The list of objects is returned.
> PyList.
>
> But I can't see how to convert PyObject as element of PyList to c++
> data type or even how to convert or iterate PyList which is PyObject
> too.
>
> Please, whisper me the proper way I will go for.

You mentioned using SWIG, but I'd actually suggest using Cython instead. It 
will make it a lot easier (and faster) for you to convert data types 
between Python and C/C++ (and will also allow you to skip over most 
ref-counting problems). Since you appear to know C++ anyway, you should be 
able to get comfortable with it quite quickly.

http://cython.org

Stefan




More information about the Python-list mailing list