still struggling, howto use a list-element as a name ? Sory, hit send button to early
Gabriel Genellina
gagsl-py at yahoo.com.ar
Sun Jan 7 12:43:00 EST 2007
Stef Mientki ha escrito:
> class LED (device):
> pinlist ={
> # pin name type init-value other-parameters
> 1: ('Cathode', _DIG_IN, [], _par2),
> 2: ('Anode', _DIG_OUT, [], _par33)
> }
>
> Status = {True:('On'), False:('Off')}
>
> def execute (self):
> old = self.On
> self.On = (~self.Cathode.Value & self.Anode.Value) > 0
> if self.On <> old : print self.Name, self.Status[self.On]
I don't know of what type are those values (certainly the're not []
because ~[] won't work). But note that using ~ with apparently logical
values doesn't work as expected. The operators &,|,^,~ are meant to be
used on integers, and work bit by bit. The operators and, or, xor, not
operate on logical, or boolean, values.
py> value = True
py> negvalue = ~value
py> if negvalue: print "oops!"
...
oops!
py> bool(negvalue)
True
If you want to express the condition "The led is ON when the value of
Anode is > 0 and the value of Cathode is < 0" that would be
self.On = self.Anode.Value>0 and self.Cathode.Value<0
but since I don't know the types of values involved I'm not sure if
this expression is right.
--
Gabriel Genellina
More information about the Python-list
mailing list