Bdfy
Bdfy

Reputation: 24729

How to use c structure in python "?

I have a simple C function.

typedef struct {
    long unsigned int First;
    long unsigned int Second;
    int c;
} FRAGMENTS;

struct out {
    long unsigned int Four;
    FRAGMENTS fragments[10000];
};
struct out test() {
    struct out *out = (struct out *)malloc(sizeof(struct out));
    ...
    return *out
}

How to use this function in Python ? Any example for transform this structure to python object ( using python wrapper ) ?

Upvotes: 3

Views: 6673

Answers (2)

James O'Doherty
James O'Doherty

Reputation: 2246

The easiest way is to use SWIG to generate a Python wrapper around your C code. You can also use it to generate bindings/wrappers for lots of other scripting languages to.

Upvotes: 1

Martin Thurau
Martin Thurau

Reputation: 7654

Do you have the data already "in" Python (i.e. from the network or a binary file)? Than you an use the struct module.

Upvotes: 1

Related Questions