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

Stef Mientki S.Mientki-nospam at mailbox.kun.nl
Sat Jan 6 13:49:52 EST 2007


In the example below, "pin" is an object with a number of properties.
Now I want
1- an easy way to create objects that contains a number of these "pin"
2- an multiple way to access these "pin", i.e.
         device.pin[some_index]
	device.some_logical_name
ad 1:
a dictionary (as "pinlist" in the example) seems a very convenient 
     way (from a viewpoint of the device creator).
As you can see in the "__init__" section this dictionary can easily be 
transported to the pin-objects.

ad 2:
THAT's the problem: how do automate these lines "self.GND = self.pin[0]"

I'm also in for other solutions.

thanks,
Stef


class Power_Supply(device):
     pinlist = {
         0: ('GND', _DIG_OUT, _par2),
         1: ('VCC', _DIG_OUT, _par33)
         }

     def __init__(self):
         # store pin-names and pin-parameters in pins
         for k in self.pinlist.keys():
           self.pin[k].Name = self.pinlist[k][0]
           self.pin[k].Value = self.pinlist[k][2]

         # for some pins, we also want to be able to use logical names
         # HOW TO USE SOMETHING like
         #     "self.pinlist[0] = self.pin[0]"
         # INSTEAD OF
         self.GND = self.pin[0]
         self.VCC = self.pin[1]

# create a Power_Supply instance and
# test if pins can be referenced in
Power = Power_Supply()
netlist1 = ( Power.VCC, Power.pin[1], Power.GND, Power.pin[0] )



More information about the Python-list mailing list