[Baypiggies] introspecting for generator vs non-generator function

Matt Good matt at matt-good.net
Sat Nov 15 04:44:12 CET 2008

On Nov 14, 2008, at 4:07 PM, Alex Martelli wrote:

> Just in case anybody's interested, please see
> http://aleaxit.blogspot.com/2008/11/python-introspecting-for-generator-vs.html

There's a co_flags for that:
"The following flag bits are defined for co_flags: ... bit 0x20 is set  
if the function is a generator."

def is_generator(func):
   return bool(func.func_code.co_flags & 0x20)

I also tried posting a comment, but maybe it's awaiting moderation.

-- Matt

More information about the Baypiggies mailing list