Invisible function attributes
Olivier Lefevre
lefevrol at yahoo.com
Thu Sep 11 11:24:46 EDT 2003
> Python has no declarations, only executable statements.
I think this was the key to my confusion in this case.
> >>> bar(4)
> Traceback (most recent call last):
> TypeError: 'int' object has only read-only attributes (assign to .a)
The way I read this, it says that a was bound to the name foo,
not to the function foo stood for at the time of that function's
definition; you are saying as much. Thus "foo.a" has to be looked
up and resolved anew for each call. This must be costly. Why was
it done this way?
OTOH I read the func attr PEP and it says that they are
implemented via a dict inside the function object. If so,
shouldn't they be bound to the function object rather than
to its name?? Or is func_dict itself an attribute?
-- O.L.
More information about the Python-list
mailing list