How to recognize a generator function?
Martin v. Löwis
martin at v.loewis.de
Wed Jun 18 16:33:29 EDT 2003
Oscar Rambla <tecnic at codidoc.com> writes:
> The question is the following:
>
> def isGeneratorfunction():
>
> return True
This isn't really a question, but I interpret it as "How can I
implement isGeneratorfunction, assuming it would take a single
argument"
The answer to that question is
CO_GENERATOR=0x0020
def isGeneratorfunction(f):
return (f.func_code.co_flags & CO_GENERATOR) != 0
Regards,
Martin
More information about the Python-list
mailing list