Plain Python function are very often more powerful than classes: >>> def go(count): ... if not hasattr(go, 'count'): ... go.count = count ... if go.count <= 0: ... del go.count ... return False ... go.count -= 1 ... return True ... >>> while go(3): ... print 'hello' ... hello hello hello >>>