[Python-Dev] Object customization
Tim Peters
tim_one@email.msn.com
Sat, 15 Apr 2000 13:43:05 -0400
[/F]
> -0.90000000000000002 on documenting this as "this
> can be used to store static data in a function"
-1 on that part from me. I never recommended to do it, I merely predicted
that people *will* do it. And, they will.
> +1 on the feature itself.
I remain +0.
[Barry]
> Works for me! I think function attrs would be a lousy place to put
> statics anyway.
Yes, but the alternatives are also lousy: a global, or abusing default
args.
def f():
f.n = f.n + 1
return 42
f.n = 0
...
print "f called", f.n, "times"
vs
_f_n = 0
def f():
global _f_n
_f_n = _f_n + 1
return 42
...
print "f called", _f_n, "times"
vs
def f(n=[0]):
n[0] = n[0] + 1
return 42
...
print "f called ??? times"
As soon as s person bumps into the first way, they're likely to adopt it,
simply because it's less lousy than the others on first sight.