Re: Equivalent to C bitmasks and enumerations

2009-04-20 Thread Ulrich Eckhardt
Ulrich Eckhardt wrote: [how to handle bitfields and enumerations in Python] Thanks to all that answered. The important lessons I learned: * You can modify classes, other than in C++ where they are statically defined. This allows e.g. adding constants. * __repr__ should provide output suitable as

Re: Equivalent to C bitmasks and enumerations

2009-04-16 Thread Dave Angel
John Machin wrote: On Apr 16, 10:13 am, Dave Angel wrote: For the Color example, how's this for a starting place: class Color(object): def __init__(self, name, enum): self.enum =num self.name =ame setattr(Color, name, self) @staticmethod def seal():

Re: Equivalent to C bitmasks and enumerations

2009-04-15 Thread John Machin
On Apr 16, 10:13 am, Dave Angel wrote: > > For the Color example, how's this for a starting place: > > class Color(object): >     def __init__(self, name, enum): >         self.enum = enum >         self.name = name >         setattr(Color, name, self) > >     @staticmethod >     def seal(): >    

Re: Equivalent to C bitmasks and enumerations

2009-04-15 Thread Dave Angel
Ulrich Eckhardt wrote: Greetings! I'm currently using Python to implement a set of tests for code that is otherwise written in C. This code was wrapped using Boost.Python and is then loaded into Python as module. What I often have in C is this: // bitfield (several flags combined) #define

Re: Equivalent to C bitmasks and enumerations

2009-04-15 Thread Wojtek Walczak
On Wed, 15 Apr 2009 12:51:31 +0200, Ulrich Eckhardt wrote: Hi, > I'm currently using Python to implement a set of tests for code that is > otherwise written in C. This code was wrapped using Boost.Python and is > then loaded into Python as module. ... > What I'm looking for is a suggestion how to

Re: Equivalent to C bitmasks and enumerations

2009-04-15 Thread Scott David Daniels
Ulrich Eckhardt wrote: Greetings! I'm currently using Python to implement a set of tests for code that is otherwise written in C. This code was wrapped using Boost.Python and is then loaded into Python as module. What I often have in C is this: // bitfield (several flags combined) #define

Equivalent to C bitmasks and enumerations

2009-04-15 Thread Ulrich Eckhardt
Greetings! I'm currently using Python to implement a set of tests for code that is otherwise written in C. This code was wrapped using Boost.Python and is then loaded into Python as module. What I often have in C is this: // bitfield (several flags combined) #define STATUS_OVERTEMP 1u #def