isgenerator(...) - anywhere to be found?
Stefan Rank
list-ener at strank.info
Tue Jan 22 08:46:00 EST 2008
on 22.01.2008 14:20 Diez B. Roggisch said the following:
>
> def isgenerator(v):
> def _g(): yield
> return type(v) == type(_g())
>
> But I wonder why there is no such method already available?
This tests for generator objects, and you could also use::
return type(v) is types.GeneratorType
I think that this is pretty direct already.
I also need to test for generator functions from time to time for which
I use::
def _isaGeneratorFunction(func):
'''Check the bitmask of `func` for the magic generator flag.'''
return bool(func.func_code.co_flags & CO_GENERATOR)
cheers,
stefan
More information about the Python-list
mailing list