. Python 2.1 function attributes

Tim Peters tim.one at home.com
Sat Jan 27 00:55:58 EST 2001


[Roy Katz]
> My question is this:
>
>    what is the point of letting functions have attributes when
>    the same role is fulfilled cleanly by classes which implement
>    __call__()?

Akin to the same point as for letting people write

    x + 2

when they could be restricted to writing

    x + 1 + 1

That is, convenience, clarity, efficiency and naturalness.  As PEP 228 says,
people *have* been abusing docstrings for all sorts of things, despite that
they're well aware of class-base techniques.  If I want to associate data
(other than a docstring, which is easy) with a function or method, first
burying the function in an artificial singleton class and then using an
instance of that class instead is simply convoluted in comparison.





More information about the Python-list mailing list