imho wrote:
> Hi all.
> 
> Is there a way to know if a function object is actually a "generator 
> function" or not ? e.g.:
> 
> def f():
>       pass
> 
> def g():
>       yield None
> 
> f.__class__ is the same as g.__class__ , i.e. "function" type.
> But i "know" that the second, when invoked, returns a generator object, 
> because there is a "yield" statement in its body.
> 
> Is there a (eventually hackish) method to get such information ?

>>> f.func_code.co_flags
67
>>> g.func_code.co_flags
99

=> 32 (CO_GENERATOR in compiler.consts) is the flag that indicates a
generator code object.

Georg
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to