Is it possible to add a variable element / method to a Python generator?
I want something in the following lines so that I can "peek" into member variable j:
def foo(): for i in range(10): self.j = 10 - i yield i gen = foo() for k in gen: print gen.j print k
Yes, I know that I can return AND j every time. But I do not want to do this. I want to look into a local generator.
python generator local
Joseph Turian
source share