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

Hongtian hongtian.info at gmail.com
Thu Oct 16 16:10:52 CEST 2008


Not exactly.

In my C/C++ application, I have following function or flow:

void func1(....)
{
    call PyFunc(struct Tdemo, struct &Tdemo1);
}

I mean I want to invoke Python function 'PyFunc' and transfer a data
structure 'Tdemo' to this function. After some process in Python, I
want it return 'Tdemo1' back to the C/C++ application.

I research boost.python and think it is not a reasonable solution
because it make the C/C++ application too complex.

Thanks.

On Oct 16, 12:09 pm, "Aaron \"Castironpi\" Brady"
<castiro... at gmail.com> wrote:
> 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