<span class="gmail_quote"></span>You would use setattr to bind a name that you don't know:<br><br>for pin in self.pin:<br> setattr(self,pin.Name,pin.Value)<br><br>However, I'm not sure why you're using a dictionary in this way. I don't totally understand the context, so I may be wrong, but I would code it more like this:
<br><br>class Power_Supply(device):<br> pins = {'GND':(_DIG_OUT,_par2),'VCC':(_DIG_OUT,_par33)}<br> def __init__(self):<br> for pin in pins.items(): #pin will be key,value<br> setattr(self,pin[0],pin[1])
<br><br>or even:<br><br>class Power_Supply(device):<br>
pins = {'GND':(_DIG_OUT,_par2),'VCC':(_DIG_OUT,_par33)}<br>
def __init__(self):<br>
self.__dict__.update(pins) <br>#self.__dict__ is the name mapping for any object, update will insert any new values from a new dictionary into the old one<br>