[Tutor] OK, let me revamp my earlier question
Doug Stanfield
DOUGS@oceanic.com
Wed, 9 Jun 1999 05:53:38 -1000
If you want to iterate over your dials, you need to get them in a data
structure, in the Panel class, that can be iterated over with a for
statement.
class Panel:
def __init__(self):
dial1 = Dial(100)
dial2 = Dial(75)
dial3 = Dial(90)
dial4 = Dial(60)
dial5 = Dial(65)
self.dials = [dial1, dial2, dial3, dial4, dial5]
def updateNormal():
for dial in self.dials:
<some code to do what you want, uses the variable 'dial' to
reference each of the Dial class instances in the list>
-Doug-
> -----Original Message-----
> From: Kenneth M. Power [mailto:teroc@zianet.com]
> Sent: Wednesday, June 09, 1999 5:13 AM
> To: tutor@python.org
> Subject: [Tutor] OK, let me revamp my earlier question
>
>
> My previous question was a bomb. The consequences of not thinking a
> matter through before posting :)/ Anyway, here is a more thorough, and
> spamless, example of what I want to accomplish, along with a small
> example in C++ (since I know how to accomplish it easily in that
> language):
>
> class Dial:
> def __init__(self, bar):
> self.current = 0
> self.limit = bar
> self.normal = 0
> self.misc1 = 0
> self.misc2 = 0
> self.total = self.normal + self.misc1 + self.misc2
>
> class Panel:
> def __init__(self):
> dial1 = Dial(100)
> dial2 = Dial(75)
> dial3 = Dial(90)
> dial4 = Dial(60)
> dial5 = Dial(65)
> #This arrangment 'simulates' dials and their settings. The range limit
> is passed to the
> #class instance on creation.
> def setInitial(self, start):
> dial1.current, dial2.current, dial3.current, dial4.current,
> dial5.current = start
> #Here the user set the starting position for each dial, that is
> sent to the class
> #instance 'variables'(? I always get some of these therms
> confused).
> updateNormal()
> def updateNormal():
> #Here is where I have problems. This function should take each
> dial instance
> #and compute the normal setting based on the current setting. In
> c++ I could
> #accomplish this very simply by using arrays and a for loop:
> #c++ example-
> #class Panel{
> # private:
> # Dial dial[6];
> # ..../buch of other class junk
> #void Panel::updateNormal(){
> # for(int i = 0; i<6; i++)
> # dial[i].setNormal(data.getNormal(dial[i].showCurrent());
> #
> # Please no comments on the strangeness of that c++ code. It's
> horrible I know,
> #but it is a quick way of doing it. So my question at
> this point,
> how do I iterate
> #through each dial instance (dial1-5), setting the 'normal'
> varable. A note-I
> #know I could just hardcode this, but I am looking for
> a way to do
> this no
> #matter the number of dials I have(one time I may have 5 dials,
> another time
> #100!) Please any suggestions.
>
> Ken
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
>