a = 42


class Foo(object):

    def __init__(self):
        self.c = 42

def foo(self):
    b = 42
yield a
yield b
yield self.c
print(list(Foo().foo()))
How to make Python generators as fast as possible?