How does a generator object refer to itself?

Michele Simionato michele.simionato at gmail.com
Thu May 25 03:42:17 EDT 2006


Why don't you use a class ?

class MyGen(object):
    def __iter__(self):
        for i in range(2):
            yield "I know who I am %s" % self

gen_obj = MyGen()

for x in gen_obj:
    print x

For language lawyers: strictly speaking gen_obj is not a generator
object (since it is
restartable) but it may work for you anyway.
  

      Michele Simionato




More information about the Python-list mailing list