python data types in c++ code

A

Arthur Mc Coy

Hi all,


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.
Be happy :)

Arthur
 
S

Stefan Behnel

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
 
A

Arthur Mc Coy

Ok people,


I do:
for (Py_ssize_t i = 0; i< PyList_Size(py_list); ++i) {
PuObject* obj = PyList_GetItem(py_list, i);
if (obj != NULL) {
// howto get obj properties of different types
(map, list, string, int, bool) ?
}
}

Very clear code. The question is in the comment :)
Let's play more,
it's like jazz,
let's explore,
Baby baby baby bass


Keep yourselves,
Arthur
 
A

Arthur Mc Coy

Stefan, great suggestion !!

I will definitely bookmark this page and consider later. But my
project dictate me use SWIG. I'm almost near the happy subend. Very
curios on question I asked in previous message.

Dear all, I love you too much :)

Arthur
 
A

Arthur Mc Coy

Stephan, you are lead developer over there :))) It's marketing,
however very nice solution.. I will propose my bosses to rediscover
their world assumptions. You know, they are still using SVN, they are
very loosely coupled to the past. I have to wash their brains...

Meantime still battling with PyObject properties which are so diverse
and disperse that I don't know...


Keep talking guys


Arthur
 
S

Stefan Behnel

Arthur Mc Coy, 06.03.2011 19:07:
Stephan, you are lead developer over there :))) It's marketing,

Let's say, as a core developer of Cython, I'm well aware of it's virtues,
and I can tell you that my suggestion is actually well backed by the user
feedback we get. You will find some of it on the right side of cython.org.
The selection there is obviously biased, but I can confirm that it really
matches with most of the non-technical feedback we get. Cython has a lot of
happy users, and that's very rewarding to its core developers.

Stefan
 
S

Stefan Behnel

Dan Stromberg, 07.03.2011 03:47:
about SVN: I'm not sure it's really dying.

I hope it will.

Yes, a lot of distributed
development has moved off of SVN, and is better off for having done so, but
I believe some environments (especially corporate environments) just prefer
having a central server.

DVCSs do not prevent you from having a central server. They just keep you
from having to rely on it. That's a big plus, also in corporate environments.

Worth a read: http://hginit.com/00.html

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top