Maric Michaud wrote: > def bit(): > def fset(self, value): > index = 5 > value = ( value & 1L ) << index > mask = ( 1L ) << index > self._d = ( self._d & ~mask ) | value > def fget(self): > index = 5 > return ( self._d >> index ) & 1 > return property(**locals()) > > > class cpu_ports(object) : > > p1 = bit() > p2 = bit() > p3 = bit() > p4 = bit() > p5 = bit() > Looks good, but I miss the index :-( p3 = bit(3)
I tried several of these kind of constructs, but I can't find a way to pass the index of the bit, all trials gave Python errors. This is obvious above my level of knowledge. So if this isn't possible, I just use the 8 copies ;-) > But i wonder if you shouldn't use arrays instead : > > In [6]:import array > > In [7]:help(array) > I don't think arrays will help, because most operations will be done on a complete byte. btw, the first notes about what I'm planning to do, can be seen here: http://oase.uci.ru.nl/~mientki/data_www/pic/jalcc/python/jal_simulation.html thanks, Stef Mientki > > > -- http://mail.python.org/mailman/listinfo/python-list