Op 02-12-15 om 10:23 schreef Chris Angelico: > On Wed, Dec 2, 2015 at 7:21 PM, Antoon Pardon > <antoon.par...@rece.vub.ac.be> wrote: >> I think python is unsuited for an obvious solution for static locals. >> Because you need to initialise your static variable somewhere. If you >> initialise whithin the body of your function, you will have a statement >> that is essentialy a declaration instead of an executable statement. >> Which goes totally against the dynamic nature op python. > It ought to be initialized at the same time the function is defined - > just like argument defaults, only without them being visible as > arguments.
I am not talking about the time. That could be done with something declarative too. I am talking about where to put in the code. > If Python had a keyword that meant > "currently-executing-function", that would work out well for > attributes (and might also make recursion more optimizable); > otherwise, default args are probably the cleanest way we have. No it wouldn't. Lets call that keyword cef. The fact that you can write: def foo(): cef.attr instead of def foo() foo.attr changes nothing about foo.attr being globally accessible. -- Antoon. -- https://mail.python.org/mailman/listinfo/python-list