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

rzed rzantow at gmail.com
Sat Jan 6 16:55:45 EST 2007


Stef Mientki <S.Mientki-nospam at mailbox.kun.nl> wrote in news:182cf
$45a00556$d443bb3a$17174 at news.speedlinq.nl:

>>> 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.
> 

Whatever works for you. In your original example, you first 
created "pinlist" (which is actually a Python dict), and then used 
it to place values in an unspecified type named "pin" (which I 
took to be another dict). I just combined the two steps.

You talk about the "pinlist" being easier ... I'm not sure what 
you mean. Easier to create? Maybe. But if you are then going to 
assign the values to names, then it doesn't strike me as easier to 
go through the two-step process. But as I said, I may be confused 
about what you are really trying to do.

> 
>>         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]

I'm glad it helped.

-- 
rzed



More information about the Python-list mailing list