Python C API, building a module

P.F.C. passionateforchrist at
Sat Nov 28 04:13:57 CET 2009

Hello, I'm new to the mailing list but have been using python for a while.

I am now attempting to embed the interpreter into a C application but am
having an issue when building a module exposing my application's functions
to python.
I do not know if this is the right place to ask for help with it, if it
isn't then please let me know where to go.

the problem I'm having is with making a PyMethodDef array
When I make the array like this it works:

static PyMethodDef ge_methods[]={
  {"test",ge_test,METH_NOARGS,"Test returns 123L"},

but as soon as I try to build the array from constant variables like this:

const int ge_test_args = METH_NOARGS;                       //The flag for
this function
const char* ge_test_doc = "Test\nwill print \"test\"";        //The
static PyMethodDef ge_methods[]={
   {"test",ge_test, ge_test_args, ge_test_doc},                //simply
replacing the flag and the docstring with a constant variable

the compiler then gives the following errors:
./test1.c:74: error: initializer element is not constant
./test1.c:74: error: (near initialization for ‘ge_methods[0].ml_flags’)
./test1.c:74: error: initializer element is not constant
./test1.c:74: error: (near initialization for ‘ge_methods[0].ml_doc’)

I'm using the gcc compiler

This may well be because of my lack of understanding the C language but I
was hoping someone could help me out, or at least point me in the right

I also posted about this at

Thank you for any help

-- Maranatha!
PFC aka Fezzik aka GAB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list