Python evangelists unite!

Jyrinx jyrinxatmindspringdotcom
Wed Dec 5 00:29:30 EST 2001


> The *real* advantage for dynamically adding methods/attributes to an
object, comes
> when you don't have control over the original object.
>
> If I have a commercial library to manage some task, and I want to store
objects
> from *that* library in my own object database, then I don't have the
option of
> having library objects inherit from some Persistent root class.  In Python
this
> can be solved in two ways, one of which is mix-in multiple inheritance,
the other
> of which is dynamically adding whatever methods and attributes are needed,
as they
> are needed.
>
> In other words, it's not a solution for avoiding baggage, it's a solution
for not
> being *able* to put the needed "baggage" in place.   :)

Gotcha. Well, at this point I can see the use for singleton methods in an
object database, but I'm still not convinced of the need in a general
language. In a more self-contained program, how often do you suddenly find
yourself with someone else's object at runtime and need to add functionality
like that? Besides, if I may continue stubbornly to stick by my favorite
contender :-) , I should think it would be trivial to have a Python library
to add this sort of runtime extension, if it isn't easy already. (Great.
I've argued myself in a circle - Ruby supports this paradigm too well; well,
maybe it could be useful; well, it's not hard in Python either :-) ... )
Anyway, this looks to me like a useful feature best relegated to a standard
library, more than a major feature of a general-purpose language.

I could be wrong, though ... where else have you guys found singleton
methods useful?

Jyrinx
jyrinx at mindspring dot com





More information about the Python-list mailing list