How to transfer data structure or class from Python to C/C++?

Aaron "Castironpi" Brady castironpi at gmail.com
Thu Oct 16 00:09:44 EDT 2008


On Oct 15, 8:08 pm, Hongtian <hongtian.i... at gmail.com> wrote:
> Hi friends,
>
> I am a newer of Python. I want to ask below question:
>
> I have a C/C++ application and I want to use Python as its extension.
> To do that, I have to transfer some data structure from C/C++
> application to Python and get some data structure from Python to C/C++
> application. I have researched Python document, but the example only
> describes how to transfer some simple data, such as integer,char,
> etc.
>
> Could you please guide me to do that? or tell me some document to have
> a research?
>
> Thanks.

Take this for what it's worth.  If I understand correctly, you want
this:

struct info {
  char* name;
  char* address;
  int age;
};

int main( ) {
  info A, B;
  python_run( "\
from urllib import urlget\n\
from mylib import populate_struct\n\
page= urlget( 'http://something' )\n\
populate_struct( page, A )\n\
populate_struct( page, B )\n" );
  if( A.age> B.age ) {
    something_in_C( );
  }
  return 0;
}

Am I on the right track?  Do you have any questions so far?



More information about the Python-list mailing list