How to use C enum in Python CTypes?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Aug 7 05:19:09 EDT 2007


On Tue, 07 Aug 2007 02:13:38 -0700, rozniy wrote:

> On Aug 7, 2:11 pm, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
>> On Tue, 07 Aug 2007 04:57:19 +0000, rozniy wrote:
>> > This site
>> >http://python.net/crew/theller/ctypes/tutorial.html#bugs-todo-and-non...
>>
>> > says that enumeration types is not implemented,
>> > "Enumeration types are not implemented. You can do it easily yourself,
>> > using c_int as the base class."
>>
>> I would just define constants:
>>
>> (OLSS_AD,
>>  OLSS_DA,
>>  OLSS_DIN,
>>  OLSS_DOUT,
>>  OLSS_SRL,
>>  OLSS_CT) = map(ctypes.c_int, xrange(6))
> 
> Wouldn't that assign integer values 0 to 5 to the things?

Yes.

> I don't know if it'll give me the correct results.

It should.  Enumerations in C are more or less just integer constants.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list