How to recognize a generator function?

Bengt Richter bokr at
Wed Jun 18 22:46:50 CEST 2003

On Wed, 18 Jun 2003 13:20:53 -0700, Oscar Rambla <tecnic at> wrote:

>-Andrew. answered.
>>How do you know what *any* function returns before you call it?
>I'll try to explain me better. Supose :
># a generator-function
>def f():
>  a =3D 1
>  yield a
># a kind of callback
>def call( object )
>  if isGeneratorfunction( object):
>      g =3D object()
>  elif Type(object) is GeneratorType:
>call( f )
>The question is the following:
>def isGeneratorfunction():
>   return True

But why would anyone pass a generator object to call if call
was designed to take a no-parameter callable as its argument?

say gen =f() from above. Why not just pass instead of gen?
(or just write fgen = f().next and pass fgen instead of
I.e., the bound method (note no parens on, which is callable
just like a function would be, and no test inside call would be necessary.

Bengt Richter

More information about the Python-list mailing list