Re: still struggling, howto use a list-element as a name ? Sory, hit send button to early

2007-01-07 Thread Jussi Salmela
Stef Mientki kirjoitti: In this exercise, I don't attempt to write beautiful Python code, but the first thing is to write a simple user-interface for non-Pythians. I understand that standardization about naming conventions is important, but the purpose here is to serve the user, who has to

Re: still struggling, howto use a list-element as a name ? Sory, hit send button to early

2007-01-07 Thread Gabriel Genellina
Stef Mientki ha escrito: class LED (device): pinlist ={ # pinname type init-value other-parameters 1: ('Cathode', _DIG_IN, [], _par2), 2: ('Anode', _DIG_OUT, [], _par33) } Status = {True:('On'), False:('Off')} def

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

2007-01-06 Thread Stef Mientki
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

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

2007-01-06 Thread Patrick Mullen
You would use setattr to bind a name that you don't know: for pin in self.pin: setattr(self,pin.Name,pin.Value) 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: class

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

2007-01-06 Thread rzed
Stef Mientki [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: 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]

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

2007-01-06 Thread Stef Mientki
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.)

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

2007-01-06 Thread Bruno Desthuilliers
Stef Mientki a écrit : 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

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

2007-01-06 Thread rzed
Stef Mientki [EMAIL PROTECTED] wrote in news:182cf [EMAIL PROTECTED]: 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

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

2007-01-06 Thread Bruno Desthuilliers
Stef Mientki a écrit : rzed wrote: (snip) 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

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

2007-01-06 Thread Bruno Desthuilliers
rzed a écrit : (snip) for k in self.pin.keys(): self.__dict__[self.pin[k]['Name']] = self.pin[k] for pin self.pin.values(): self.__dict__[pin['name']] = pin -- http://mail.python.org/mailman/listinfo/python-list

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

2007-01-06 Thread Jussi Salmela
Bruno Desthuilliers kirjoitti: Stef Mientki a écrit : 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]

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

2007-01-06 Thread Stef Mientki
Jussi Salmela wrote: Bruno Desthuilliers kirjoitti: Stef Mientki a écrit : 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.

Re: still struggling, howto use a list-element as a name ? Sory, hit send button to early

2007-01-06 Thread Stef Mientki
Stef Mientki wrote: Jussi Salmela wrote: Bruno Desthuilliers kirjoitti: Stef Mientki a écrit : 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.

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

2007-01-06 Thread rzed
Bruno Desthuilliers [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: rzed a écrit : (snip) for k in self.pin.keys(): self.__dict__[self.pin[k]['Name']] = self.pin[k] for pin self.pin.values(): self.__dict__[pin['name']] = pin D'oh! Of course! Thank you. --