python data types in c++ code

Discussion in 'Python' started by Arthur Mc Coy, Mar 6, 2011.

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

    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

    Please, whisper me the proper way I will go for.
    Be happy :)

    Arthur Mc Coy, Mar 6, 2011
    1. Advertisements

  2. Arthur Mc Coy, 06.03.2011 17:40:
    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.

    Stefan Behnel, Mar 6, 2011
    1. Advertisements

  3. 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 Mc Coy, Mar 6, 2011
  4. 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 Mc Coy, Mar 6, 2011
  5. 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 Mc Coy, Mar 6, 2011
  6. In short, the answer is to use PyObject dictionary ?
    Arthur Mc Coy, Mar 6, 2011
  7. Arthur Mc Coy, 06.03.2011 19:07:
    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
    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 Behnel, Mar 6, 2011
  8. Dan Stromberg, 07.03.2011 03:47:
    I hope it will.

    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:

    Stefan Behnel, Mar 7, 2011
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.