How to recognise "generator functions" ?

imho certo at comeno.it
Wed Jul 19 18:01:33 EDT 2006


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 ?

Thanks in advance,

Diego.



More information about the Python-list mailing list