How to declare python ints in C extensions?

Tony Houghton h at realh.co.uk
Sun Jan 4 19:20:31 CET 2009


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. The docs only seem to tell you how
to define functions/methods and new types.

For example, where the kernel header dvb/frontend.h defines:

typedef enum fe_type {
	FE_QPSK,
	FE_QAM,
	FE_OFDM,
	FE_ATSC
} fe_type_t;

I want to make them available as if there was a python module
dvb/frontend.py containing:

FE_QPSK = 0
FE_QAM = 1
FE_OFDM = 2
FE_ATSC = 3

but in real life the module would be dvb/frontendmodule.c.

-- 
TH * http://www.realh.co.uk




More information about the Python-list mailing list