Can I add a member variable / method to a Python generator?
I want something along the following lines, so that I can "peek" at 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 i AND j every time. But I don't want to do that. I want to peek at a local within the generator.