On Sat, Dec 24, 2011 at 9:32 AM, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > Yes. But having to manage it *by hand* is still unclean:
Well, my point was that Python's current behaviour _is_ that. > * you still have to assign the default value to the function assignment > outside the function, which is inelegant; C's static variables are initialized inside the function. But since Python doesn't have that, it doesn't really work that way. (You might be able to use a decorator to do some cool tricks though.) > * if you rename the function, the internal lookup func.default_value will > fail. Python would benefit some from a "current-function" reference, if tricks like this were to be encouraged. It'd help with recursion too. hmmmm... >>> def Y(func): return lambda *args,**kwargs: func(func,*args,**kwargs) >>> @Y def foo(me,x): if x>5: return x return me(me,x+1),7,x >>> foo(3) (((6, 7, 5), 7, 4), 7, 3) Useful? Not very. Maybe as a language feature, but not as a parameter. But of curiosity value. ChrisA -- http://mail.python.org/mailman/listinfo/python-list