Peter Otten wrote:
> Stef Mientki wrote:
>
>> Maric Michaud wrote:
>
> def bit(index):
>>> def fset(self, value):
>
>>> value = ( value & 1L ) << index
>>> mask = ( 1L ) << index
>>> self._d = ( self._d & ~mask ) | value
>>> def fget(self):
>
>>> return ( self._d >> index ) & 1
>>> return property(**locals())
>>>
>>>
>>> class cpu_ports(object) :
>
> p1 = bit(1)
> p2 = bit(2)
> p3 = bit(3)
> p4 = bit(4)
> p5 = bit(5)
>
>> Looks good, but I miss the index :-(
>
> No more.
agreed,
but Python doesn't like it,
and I don't understand why
def bit(index):
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(1)
p2 = bit(2)
p3 = bit(3)
p4 = bit(4)
p5 = bit(5)
Traceback (most recent call last):
File "<string>", line 209, in run_nodebug
File "D:\data_to_test\rapid_prototyping_board_16F877.py", line 168, in ?
class cpu_ports(object) :
File "D:\data_to_test\rapid_prototyping_board_16F877.py", line 169, in
cpu_ports
p1 = bit(1)
File "D:\data_to_test\rapid_prototyping_board_16F877.py", line 166, in bit
return property(**locals())
TypeError: 'index' is an invalid keyword argument for this function
but anyway thanks
Stef
>
> Peter
--
http://mail.python.org/mailman/listinfo/python-list