Question about generators.

Paul McGuire ptmcg at austin.rr._bogus_.com
Mon Jan 30 14:14:00 EST 2006


<kiwwisk at gmail.com> wrote in message
news:1138647550.393340.51170 at z14g2000cwz.googlegroups.com...
> Hi,
> Is there a way for created generators to determine what function
> created them?
> Like for objects and classes function 'isinstance',
>
> e.g.:
>
> def gen1( ):
>    yield 1
>
> a = gen1( )
>
> if isinstance( a, gen1 ) == True: #not functional.
>    ...
>
> Thanks for reply,
>        Andrej
>

How's this? (Written using Python 2.4)
-- Paul

>>> def gen1():
...     yield 1
...
>>> a = gen1()
>>> a.gi_frame.f_code.co_name
'gen1'
>>>





More information about the Python-list mailing list