[Python-ideas] Allow lambda decorators
spir
denis.spir at free.fr
Mon Feb 9 16:23:13 CET 2009
Le Mon, 09 Feb 2009 08:32:46 -0600,
Ron Adam <rrr at ronadam.com> a écrit :
> >>> class obj(object):
> ... def __init__(self):
> ... self.i = i
> ... def __call__(self):
> ... return self.i
> ...
> >>> objs = [obj() for i in range(10)]
> >>> [v() for v in objs]
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>
> Because the value is stored on the object at the time the object is
> created, vs when it is called, this works as expected.
I see this formulation equivalent to "def f(i=i0): return i", I mean conceptually. From an OO point of view, a default/keyword arg is indeed an (implicit) attribute of a function, evaluated at definition/creation time. Actually, isn't the above code an excellent explanation of what a default argument is in python?
Denis
------
la vida e estranya
More information about the Python-ideas
mailing list