I was curious about using static variables in python, and ended up at: Why doesn't Python have static variables?
In the accepted answer, which I found informative, it is said "If you want your function's behavior to change each time it's called, what you need is a generator".
However I was a bit confused, since the example used there can be done with a class as well:
class Foo(object): def __init__(self, bar): self.bar = bar def __call__(self): self.bar = self.bar * 3 % 5 return self.bar foo = Foo(bar) print foo() print foo()
This makes more sense to me (but probably only because I haven't used generators properly before).
So my question is whether there is some other advantage to using generators over classes when the function needs to change behavior each time it's called.