Newbie asks about static variables...
Jeremy Hylton
jeremy at cnri.reston.va.us
Tue May 4 15:30:11 EDT 1999
A slight variant, which uses a little less magic, is to make
killParrot a method on an object that keeps track of the state.
class Spam:
def __init__(self):
self.no_calls = 0
def addEggs(self):
self.no_calls = self.no_calls + 1
meal = Spam()
meal.addEggs()
meal.addEggs()
assert meal.no_calls == 2
I've got nothing against __call__. I've been happy to use it on
several occasions, but methods do just fine for most things.
Jeremy
More information about the Python-list
mailing list