How to recognize a generator function?
Gonçalo Rodrigues
op73418 at mail.telepac.pt
Wed Jun 18 10:03:05 EDT 2003
On Wed, 18 Jun 2003 03:21:35 -0700, Oscar Rambla <tecnic at codidoc.com>
wrote:
>
>Hi,
>
>I'm not been able to find a solution to the following:
>
>How to recognize if a function is a generator function before calling it?
>(Alternatives to having to inspect code for a yield or wrapping it into a
>class).
>
>Note: I refer to the function, not to the generator itself.
>
>Thank you in advance.
>
>-Oscar
Let us see...
>>> from __future__ import generators
>>> def testfunc():
... return None
...
>>> testfunc
<function testfunc at 0x010F05C0>
>>> def testfunc():
... yield None
...
>>> testfunc
<function testfunc at 0x010F2750>
>>>
Hmm, it seems that short of analyzing the source code you cannot...
And then again, why are you interested in such a difference? Seems
like the typical YAGNI.
Hoping-to-be-corrected-ly-yours,
G. Rodrigues
More information about the Python-list
mailing list