def main_count():
a = 0
while True:
a += 1
yield a
def func1():
b = 0
while True:
a = yield
print('func1', a)
b += a
yield b
def func2():
c = 0
while True:
a = yield
print('func2', a)
c += a
yield c
if __name__ == '__main__':
fn1 = func1()
fn2 = func2()
next(fn1)
next(fn2)
for a in main_count():
b = fn1.send(a)
c=fn2.send(a)
next(fn1)
next(fn2)
class Counter():
def __init__(self, a = 0, b = 0, c = 0):
self.a = a
self.b = b
self.c = c
def main_count(self):
while True:
self.a += 1
yield self.a
def method1(self):
while True:
print('method1', a)
self.b += self.a
yield self.b
def method2(self):
while True:
print('method2', a)
self.c += self.a
yield self.c
if __name__ == '__main__':
counter = Counter()
method1 = counter.method1()
method2 = counter.method2()
for a in counter.main_count():
b = next(method1)
c = next(method2)