static variables
Antoon Pardon
antoon.pardon at rece.vub.ac.be
Wed Dec 2 04:47:15 EST 2015
Op 02-12-15 om 10:23 schreef Chris Angelico:
> On Wed, Dec 2, 2015 at 7:21 PM, Antoon Pardon
> <antoon.pardon at 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.
More information about the Python-list
mailing list