noddy example, writing C modules for python

Bernd Nawothnig Bernd.Nawothnig at
Wed Jun 2 14:37:36 CEST 2004

Hi Torsten,

On Sun, 30 May 2004, Torsten Mohr <tmohr at> wrote:

> based on the example module "noddy" i wrote an own one
> and i have problems accessing the elements in the python
> objects.  I defined the example object:

> typedef struct {
>   PyObject_HEAD
>   int num;
> } pmod_obj;

> static PyMemberDef pmod_members[] = {
>   {"number", T_INT, offsetof(pmod_obj, num), 0, /* LINE 143 */
>   "pmod number"},
>   {NULL}
> };

> When i compile this under Win32, i get this (in german):
> : error C2552: 'pmod_members': Initialisierung nicht
> zusammengesetzter Typen mit Initialisierungsliste ist nicht möglich
>         'PyMemberDef' : Typen mit benutzerdefinierten Konstruktoren sind
> nicht  'aggregate'

The explanation is shown quite clear in plain German - where is your
problem? :-) One is sure: your problem has nothing to do with Python
but with C++. Only for short, look at this example:

class A {
  char *s;
  A(): s("") {}
} a = {"Hallo"};

That cannot compile too because there are two different
initializations: one via constructor and the second via initialization
list. So, of course, Gnu g++ also complains: error: `a' must be initialized by constructor, not by `{...}'

HTH & f'up2


Those who desire to give up freedom in order to gain security,
will not have, nor do they deserve, either one. [T. Jefferson]

More information about the Python-list mailing list