G
Gustavo Niemeyer
Would you trade the "mutable integer" and "count(n=[0])" kludges for a
import sys
class Closure:
def __init__(self):
self.__dict__ = sys._getframe().f_back.f_locals
def getFunc():
counter = 0
c = Closure()
def count():
c.counter += 1
print c.counter
return count
c = getFunc()
c()
c()
c()
solution like &count ? Does anyone agree with me that a "closure
variable prefix" is more explicit and readable?
import sys
class Closure:
def __init__(self):
self.__dict__ = sys._getframe().f_back.f_locals
def getFunc():
counter = 0
c = Closure()
def count():
c.counter += 1
print c.counter
return count
c = getFunc()
c()
c()
c()