Does anyone else use this little idiom?

Ivan Illarionov ivan.illarionov at gmail.com
Sun Feb 3 14:33:16 CET 2008


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
>>>



More information about the Python-list mailing list