How to recognize a generator function?
bokr at oz.net
Wed Jun 18 22:46:50 CEST 2003
On Wed, 18 Jun 2003 13:20:53 -0700, Oscar Rambla <tecnic at codidoc.com> wrote:
>>How do you know what *any* function returns before you call it?
>I'll try to explain me better. Supose :
># a generator-function
> 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:
> 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 gen.next instead of gen?
(or just write fgen = f().next and pass fgen instead of gen.next).
I.e., the bound method (note no parens on gen.next), which is callable
just like a function would be, and no test inside call would be necessary.
More information about the Python-list