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.
    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
    Arthur Mc Coy, Mar 6, 2011
    #1
    1. Advertising

  2. 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
    Stefan Behnel, Mar 6, 2011
    #2
    1. Advertising

  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
    Arthur Mc Coy, Mar 6, 2011
    #3
  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
    Arthur Mc Coy, Mar 6, 2011
    #4
  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
    Arthur Mc Coy, Mar 6, 2011
    #5
  6. In short, the answer is to use PyObject dictionary ?
    Arthur Mc Coy, Mar 6, 2011
    #6
  7. 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
    Stefan Behnel, Mar 6, 2011
    #7
  8. Dan Stromberg, 07.03.2011 03:47:
    > On Sun, Mar 6, 2011 at 10:07 AM, Arthur Mc Coy wrote:
    >> You know, they are still using SVN, they are
    >> very loosely coupled to the past.

    >
    > 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
    Stefan Behnel, Mar 7, 2011
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Knight
    Replies:
    2
    Views:
    753
    Steve Knight
    Oct 10, 2003
  2. j_mckitrick
    Replies:
    2
    Views:
    564
    Cameron Laird
    Nov 13, 2004
  3. ramu
    Replies:
    2
    Views:
    323
    rlblaster
    Feb 20, 2006
  4. Gary Roach
    Replies:
    0
    Views:
    111
    Gary Roach
    Sep 1, 2013
  5. Fábio Santos
    Replies:
    0
    Views:
    120
    Fábio Santos
    Sep 4, 2013
Loading...

Share This Page