Why instancemethod when I can add functions to classes outside class body?

Martin v. Löwis martin at v.loewis.de
Fri Jul 25 23:57:02 CEST 2003


"Terry Reedy" <tjreedy at udel.edu> writes:

> So to answer the OP's question, the problem solved is that directly
> assigning a function as an instance attribute binds the function as a
> function, which means no *automatic* access to the instance and its
> other attributes.

To *really* answer the OP's question: API, in general, has no purpose
- it has a function. Whether that function is useful for something
depends on the application. So APIs don't try to solve problems
themselves - it is the developers who solve the problems using the API.

So one may ask "what is the problem that could be solved using
new.instancemethod". These questions often don't have good answers,
and I believe yours isn't much better than that the problem being
solved is

"Create an object of type instancemethod, given the function, the
instance, and the class."

Whether it is useful to create such objects depends on the
application.

Regards,
Martin





More information about the Python-list mailing list