How to recognize a generator function?

Oscar Rambla tecnic at codidoc.com
Wed Jun 18 19:33:37 EDT 2003


Martin answered:
>The answer to that question is
>
>CO_GENERATOR=0x0020
>def isGeneratorfunction(f):
>  return (f.func_code.co_flags & CO_GENERATOR) != 0

Good Martin. You got it ( until the 2.3, isn't it?) Thank you!

Neil Wrote:
>There is no way to do that.  Think about:
>There are lots of ways to return iterators in Python.
>Generator-iterators are first class objects and be passed around.
>What are you really trying to do?

That's also true. I may have been 'wondering the moon'.

But supose you have a function that receive a function as an argument and must 
decide to call it depending on ( if it's a generation-function) there is no 
other generator/iterator of this function alive.
Of course you could  look on the iterators for each function you receive but 
would be better to filter it in advance.

By the way, Do you know what's happening with Quixote mailing-list?
I've tried to send some code but it seems dead.

Gonçalo wrote:
>And then again, why are you interested in such a difference? Seems
>like the typical YAGNI.

Could you spell it, please?

Oscar Rambla
CODI

-------------------------------------------------------







More information about the Python-list mailing list