new to python - trouble calling a function from another function

nn pruebauno at latinmail.com
Fri Aug 6 10:51:22 EDT 2010


On Aug 5, 2:01 pm, Daniel Urban <urban.d... at gmail.com> wrote:
> > 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?
>
> I think the self.goUp() call is executed, the goUp function gets
> called, returns a generator object (because goUp is a generator
> function), then you don't use that generator object for anything.
>
> Daniel

Brandon, this example might help you understand the problem:

>>> def g():
	print('p1')
	yield 2
	print('p3')


>>> g()
<generator object g at 0x00F04DC8>
>>> b=g()
>>> next(b)
p1
2
>>> next(b)
p3
Traceback (most recent call last):
  File "<pyshell#24>", line 1, in <module>
    next(b)
StopIteration
>>>



More information about the Python-list mailing list