On Jan 22, 7:46 am, Stefan Rank <[EMAIL PROTECTED]> wrote:
> 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

Might want to catch AttributeError in this routine - not all func
arguments will have a func_code attribute.  See below:

class Z(object):
    def __call__(*args):
        for i in range(3):
            yield 1

for i in Z()():
    print i
# prints 1 three times

import types
print type(Z()()) == types.GeneratorType
# prints 'True'

print Z()().func_code
# raises AttributeError, doesn't have a func_code attribute

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

Reply via email to