How to declare python ints in C extensions?

Christian Heimes lists at cheimes.de
Sun Jan 4 15:05:14 EST 2009


Philip Semanchuk schrieb:
> This works for me:
>    PyModule_AddIntConstant(module, "O_CREAT", O_CREAT);
> 
> I've had to learn a lot about writing extensions from looking at the
> Python source code. Lots of valuable tricks to be learned there.

This trick makes it even easier:

#ifndef PyModule_AddIntMacro
#define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
#endif

if (!PyModule_AddIntMacro(mod, O_CREAT))
    return;

Christian




More information about the Python-list mailing list