How to declare python ints in C extensions?

Philip Semanchuk philip at semanchuk.com
Sun Jan 4 19:46:35 CET 2009


On Jan 4, 2009, at 1:20 PM, Tony Houghton wrote:

> I want to write python wrappers for the Linux DVB API. The underlying
> structures and constants may change from time to time, and some of the
> constants are generated from macros, so I think it would be better to
> write the module in C rather than just copying the constants into pure
> python code and using python's ioctl and struct modules.
>
> The trouble is I can't find out how to define a simple python int
> variable/constant in a C extension.

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.


HTH
Philip



More information about the Python-list mailing list