c to python

Gerhard Häring gh at ghaering.de
Mon May 26 14:22:57 EDT 2003


Jimmy verma wrote:
> Hi !
> 
> I have a structure in c like this
> 
> struct ab
> {
>        int a;
>        int b;
>        int *c;
>       struct d *d;
> } AB;
> 
> 
> And i am using it in my program like
> 
> void XYZ(int a , AB *b)
> 
> How can this kind of structure be translated in python code?

As far as I see, you can't. Python doesn't know about pointers, even 
with the struct module 
(http://python.org/doc/current/lib/module-struct.html).

> Your suggestions are welcomed.

It might be that you'll have to write a C extension to wrap your 
existing C code for use with Python.

If, however, you don't need any binary compatibility of your existing C 
code and you simply want an equivalent data structure in Python, then 
that's certainly easily doable.

We'd need to know why you have the 'int* c' in your C struct 
declaration, then.

-- Gerhard






More information about the Python-list mailing list