still struggling, howto use a list-element as a name ?

Stef Mientki S.Mientki-nospam at mailbox.kun.nl
Sat Jan 6 15:24:02 EST 2007


>> class Power_Supply(device):
>>      pinlist = {
>>          0: ('GND', _DIG_OUT, _par2),
>>          1: ('VCC', _DIG_OUT, _par33)
>>          }
> 
> I may be confused about what you're after, but wouldn't something 
> like this work? (I don't know what a _par2 object is; I've named 
> it something here.)
_par2, is just (a reference to) a constant
> 
> class Power_Supply(device):
>     def __init__(self):
>         self.pin = {
>             0:dict(Name='GND',Value=_DIG_OUT,something=_par2),
>             1:dict(Name='VCC',Value=_DIG_OUT,something=_par33),
>         }
Why so complex, I need 10 or more parameters (or empty),
and then this becomes completely unreadable.
As this is part of the "user interface",
(I want that completely unknown with Python people,
write these lines),
I think my "pinlist" is much easier.


>         for k in self.pin.keys():
>             self.__dict__[self.pin[k]['Name']] = self.pin[k]
thanks "rzed" ?,
that is exactly what I was looking for:
               self.__dict__[self.pinlist[k][0]] = self.pin[k]


cheers,
Stef



More information about the Python-list mailing list