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
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
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
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
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]
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.)
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
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
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
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
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]
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.
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.
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.
--
14 matches
Mail list logo