I\'d like to create a decorator like below, but I can\'t seem to think of an implementation that works. I\'m starting to think it\'s not possible, but thought I would ask yo
How about this, without decorators?
class State(dict): """Object interface to dict.""" def __getattr__(self, name): try: return self[name] except KeyError: raise AttributeError, name def f(d=State(x=0)): d.x += 1 return d.x
And here is it in action:
>>> f() 1 >>> f() 2 >>> f() 3