[Python-ideas] Tweaking closures and lexical scoping to include the function being defined
Arnaud Delobelle
arnodel at gmail.com
Mon Sep 26 15:48:07 CEST 2011
On 26 September 2011 14:03, Masklinn <masklinn at masklinn.net> wrote:
> An other thing which strikes me as weird is that the proposal is basically the
> creation of private instance attribute on functions. Could you not get the same
> by actually setting an attribute on the function (this can not be used in
> lambdas in any case)?
>
> def f():
> print(f.i)
> f.i += 1
> f.i = 17
This has been talked about before (in this thread or a related one).
It would be slower (requiring two dictionary lookups for each access,
rather than a single LOAD_DEREF / STORE_DEREF) and would break if the
name 'f' is bound to another object.
--
Arnaud
More information about the Python-ideas
mailing list