Re: new to python - trouble calling a function from another function

Discussion in 'Python' started by Jon Clements, Aug 5, 2010.

  1. Jon Clements

    Jon Clements Guest

    On 5 Aug, 08:25, Brandon McCombs <> wrote:
    > Hello,
    >
    > I'm building an elevator simulator for a class assignment. I recently
    > ran into a roadblock and don't know how to fix it. For some reason, in
    > my checkQueue function below, the call to self.goUp() is never executed.
    > It is on the last line of code I pasted in. I can put print statements
    > before and after the call and I have a print statement in goUp() itself.
    >   Only the print statements before and after the call are executed. The
    > one inside goUp() is never executed because goUp() never seems to be
    > executed. How can that be? I don't get any errors when the script
    > executes. Surely this isn't some limitation I'm encountering?
    >
    > thanks
    >
    > sorry about the formatting
    >
    > ---------------------------------------------
    > class Elevator(Process):
    > def __init__(self,name):
    >         Process.__init__(self,name=name)
    >         self.numPassengers = 0
    >         self.passengerList = []
    >         self.passengerWaitQ = []
    >         self.currentFloor = 1
    >         self.idle = 1
    >         self.newPassengers = 0
    > def goUp(self):
    >         print "here"
    >         bubbleSort(self.passengerList, len(self.passengerList))
    >         self.currentFloor += 1
    >         if len(self.passengerList) > 0:
    >            for p in self.passengerList:
    >               if self.currentFloor == p.destination:
    >                 yield (p.destination - self.currenteFloor) * TRAVELTIME, self
    >                 reactivate(p)
    >                 p.inBuilding()
    >               else:
    >                 self.goUp()
    >
    > def checkQueue(self):
    >         if (len(self.passengerWaitQ)) > 0 and len(self.passengerList) <
    > MAXCAPACITY:
    >         if len(self.passengerWaitQ) < MAXCAPACITY:
    >             self.newPassengers = len(self.passengerWaitQ)
    >         else:
    >              self.newPassengers = MAXCAPACITY - len(self.passengerList)
    >         for i in range(0,self.newPassengers):
    >           self.passengerList.append(self.passengerWaitQ.pop())
    >         self.goUp()


    Hi Brandon,

    Nice one at having a good crack at coding before posting!

    From your posted code, I'm struggling to see what's trying to be
    taught to you for this class assignment.

    As a note it'll be worth reading PEP 8 regarding naming conventions,
    because it looks very Java-ish to me!

    (I might be taking too much a real-world approach in the following,
    but do with it as you will...)

    I'm assuming that MAXCAPACITY and TRAVELTIME are globals somewhere.
    Although what I'm thinking is that different Elevators will have
    different capacities and different floors they service. An Elevator is
    *not* going to know its number of passengers (the most it could do is
    capacity based on weight restrictions) therefore it's not going to
    know the number of new passengers on each floor either.

    A couple of things that'd be worthwhile:

    1) Post the requirements for your assignment - what's it supposed to
    output etc...
    2) Go find an elevator, take a pen and pad with you, and stand in it
    for 30 mins or so, and see how the real thing deals with situations
    and make notes. ie, does it queue requests, or decide to take the next
    nearest floor, when does it stop and open etc...?

    hth

    Jon.
    Jon Clements, Aug 5, 2010
    #1
    1. Advertising

  2. On Thu, 5 Aug 2010 02:50:05 -0700 (PDT), Jon Clements
    <> declaimed the following in
    gmane.comp.python.general:

    > As a note it'll be worth reading PEP 8 regarding naming conventions,
    > because it looks very Java-ish to me!
    >

    I didn't check, but my memory insists that the Deitel Java text book
    does use an elevator simulation as it's main project... <G>

    ....

    {No, my mistake... it's their C++ book that does the elevator exercise}
    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
    Dennis Lee Bieber, Aug 6, 2010
    #2
    1. Advertising

  3. Jon Clements

    Jon Clements Guest

    On 5 Aug, 16:15, Brandon McCombs <> wrote:
    > Jon Clements wrote:
    > > On 5 Aug, 08:25, Brandon McCombs <> wrote:
    > >> Hello,

    >
    > >> I'm building an elevator simulator for a class assignment. I recently
    > >> ran into a roadblock and don't know how to fix it. For some reason, in
    > >> my checkQueue function below, the call to self.goUp() is never executed.
    > >> It is on the last line of code I pasted in. I can put print statements
    > >> before and after the call and I have a print statement in goUp() itself.
    > >>   Only the print statements before and after the call are executed. The
    > >> one inside goUp() is never executed because goUp() never seems to be
    > >> executed. How can that be? I don't get any errors when the script
    > >> executes. Surely this isn't some limitation I'm encountering?

    >
    > >> thanks

    >
    > >> sorry about the formatting

    >
    > >> ---------------------------------------------
    > >> class Elevator(Process):
    > >> def __init__(self,name):
    > >>         Process.__init__(self,name=name)
    > >>         self.numPassengers = 0
    > >>         self.passengerList = []
    > >>         self.passengerWaitQ = []
    > >>         self.currentFloor = 1
    > >>         self.idle = 1
    > >>         self.newPassengers = 0
    > >> def goUp(self):
    > >>         print "here"
    > >>         bubbleSort(self.passengerList, len(self.passengerList))
    > >>         self.currentFloor += 1
    > >>         if len(self.passengerList) > 0:
    > >>            for p in self.passengerList:
    > >>               if self.currentFloor == p.destination:
    > >>                 yield (p.destination - self.currenteFloor) * TRAVELTIME, self
    > >>                 reactivate(p)
    > >>                 p.inBuilding()
    > >>               else:
    > >>                 self.goUp()

    >
    > >> def checkQueue(self):
    > >>         if (len(self.passengerWaitQ)) > 0 and len(self.passengerList) <
    > >> MAXCAPACITY:
    > >>         if len(self.passengerWaitQ) < MAXCAPACITY:
    > >>             self.newPassengers = len(self.passengerWaitQ)
    > >>         else:
    > >>              self.newPassengers = MAXCAPACITY - len(self.passengerList)
    > >>         for i in range(0,self.newPassengers):
    > >>           self.passengerList.append(self.passengerWaitQ.pop())
    > >>         self.goUp()

    >
    > > Hi Brandon,

    >
    > > Nice one at having a good crack at coding before posting!

    >
    > > From your posted code, I'm struggling to see what's trying to be
    > > taught to you for this class assignment.

    >
    > not relevant at this point
    >
    >
    >
    > > As a note it'll be worth reading PEP 8 regarding naming conventions,
    > > because it looks very Java-ish to me!

    >
    > ok but not relevant
    >
    >
    >
    > > (I might be taking too much a real-world approach in the following,
    > > but do with it as you will...)

    >
    > > I'm assuming that MAXCAPACITY and TRAVELTIME are globals somewhere.
    > > Although what I'm thinking is that different Elevators will have
    > > different capacities and different floors they service. An Elevator is
    > > *not* going to know its number of passengers (the most it could do is
    > > capacity based on weight restrictions) therefore it's not going to
    > > know the number of new passengers on each floor either.

    >
    > okay but not relevant to the problem at hand
    >
    >
    >
    > > A couple of things that'd be worthwhile:

    >
    > > 1) Post the requirements for your assignment - what's it supposed to
    > > output etc...

    >
    > that isn't relevant for determining at the python level why a function
    > simply isn't being called
    >
    > > 2) Go find an elevator, take a pen and pad with you, and stand in it
    > > for 30 mins or so, and see how the real thing deals with situations
    > > and make notes. ie, does it queue requests, or decide to take the next
    > > nearest floor, when does it stop and open etc...?

    >
    > > hth

    >
    > > Jon.

    >
    > actually it doesn't help at all since you decided to focus on everything
    > but my actual question of why a function call wasn't working but rather
    > question the validity of the program itself


    Heard of something called 'sentences' that start with a capital letter
    that end with (mostly) a full stop?

    Anyway, what I suggested was that your design is massively flawed. You
    ask a group, that's friendly to newbies for help, and you receive
    advice... then "bitch" about it.

    Indeed, the intention was to make you re-think the whole program --
    then you'd have learnt more. Focusing on one thing when it's the wrong
    design anyway is a *bad thing*.

    Remember, you've posted to a list that have members that have done 30+
    years of programming in a professional role.

    Just my 2c,

    Jon.
    Jon Clements, Aug 6, 2010
    #3
  4. On Thu, Aug 5, 2010 at 8:15 AM, Brandon McCombs <> wrote:
    > Jon Clements wrote:
    >>
    >> On 5 Aug, 08:25, Brandon McCombs <> wrote:
    >>>
    >>> Hello,
    >>>
    >>> I'm building an elevator simulator for a class assignment. I recently
    >>> ran into a roadblock and don't know how to fix it. For some reason, in
    >>> my checkQueue function below, the call to self.goUp() is never executed..
    >>> It is on the last line of code I pasted in. I can put print statements
    >>> before and after the call and I have a print statement in goUp() itself..
    >>>  Only the print statements before and after the call are executed. The
    >>> one inside goUp() is never executed because goUp() never seems to be
    >>> executed. How can that be? I don't get any errors when the script
    >>> executes. Surely this isn't some limitation I'm encountering?
    >>>
    >>> thanks
    >>>
    >>> sorry about the formatting
    >>>
    >>> ---------------------------------------------
    >>> class Elevator(Process):
    >>> def __init__(self,name):
    >>>        Process.__init__(self,name=name)
    >>>        self.numPassengers = 0
    >>>        self.passengerList = []
    >>>        self.passengerWaitQ = []
    >>>        self.currentFloor = 1
    >>>        self.idle = 1
    >>>        self.newPassengers = 0
    >>> def goUp(self):
    >>>        print "here"
    >>>        bubbleSort(self.passengerList, len(self.passengerList))
    >>>        self.currentFloor += 1
    >>>        if len(self.passengerList) > 0:
    >>>           for p in self.passengerList:
    >>>              if self.currentFloor == p.destination:
    >>>                yield (p.destination - self.currenteFloor) * TRAVELTIME,
    >>> self
    >>>                reactivate(p)
    >>>                p.inBuilding()
    >>>              else:
    >>>                self.goUp()
    >>>
    >>> def checkQueue(self):
    >>>        if (len(self.passengerWaitQ)) > 0 and len(self.passengerList) <
    >>> MAXCAPACITY:
    >>>        if len(self.passengerWaitQ) < MAXCAPACITY:
    >>>            self.newPassengers = len(self.passengerWaitQ)
    >>>        else:
    >>>             self.newPassengers = MAXCAPACITY - len(self.passengerList)
    >>>        for i in range(0,self.newPassengers):
    >>>          self.passengerList.append(self.passengerWaitQ.pop())
    >>>        self.goUp()

    >>
    >> Hi Brandon,
    >>
    >> Nice one at having a good crack at coding before posting!
    >>
    >> From your posted code, I'm struggling to see what's trying to be
    >> taught to you for this class assignment.

    >
    > not relevant at this point
    >
    >>
    >> As a note it'll be worth reading PEP 8 regarding naming conventions,
    >> because it looks very Java-ish to me!

    >
    > ok but not relevant
    >
    >>
    >> (I might be taking too much a real-world approach in the following,
    >> but do with it as you will...)
    >>
    >> I'm assuming that MAXCAPACITY and TRAVELTIME are globals somewhere.
    >> Although what I'm thinking is that different Elevators will have
    >> different capacities and different floors they service. An Elevator is
    >> *not* going to know its number of passengers (the most it could do is
    >> capacity based on weight restrictions) therefore it's not going to
    >> know the number of new passengers on each floor either.

    >
    > okay but not relevant to the problem at hand
    >
    >>
    >> A couple of things that'd be worthwhile:
    >>
    >> 1) Post the requirements for your assignment - what's it supposed to
    >> output etc...

    >
    > that isn't relevant for determining at the python level why a function
    > simply isn't being called
    >
    >> 2) Go find an elevator, take a pen and pad with you, and stand in it
    >> for 30 mins or so, and see how the real thing deals with situations
    >> and make notes. ie, does it queue requests, or decide to take the next
    >> nearest floor, when does it stop and open etc...?
    >>
    >> hth
    >>
    >> Jon.
    >>

    >
    > actually it doesn't help at all since you decided to focus on everything but
    > my actual question of why a function call wasn't working but rather question
    > the validity of the program itself


    This is too bad. You looked like you were all set to be the poster
    child for how to ask a good question here, and now you've blown it.

    Geremy Condra
    geremy condra, Aug 6, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Lagemann
    Replies:
    8
    Views:
    466
    Mike Wahler
    Jan 10, 2005
  2. tiwy
    Replies:
    0
    Views:
    431
  3. Satish Chimakurthi

    Function calling another function

    Satish Chimakurthi, Mar 1, 2004, in forum: Python
    Replies:
    2
    Views:
    365
    Satish Chimakurthi
    Mar 1, 2004
  4. dutzend
    Replies:
    1
    Views:
    83
  5. Replies:
    2
    Views:
    441
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page