new.instancemethod

James_Althoff at i2.com James_Althoff at i2.com
Fri May 18 20:18:27 EDT 2001


I wrote previously:
>Alex Martelli wrote:
>>...then class 'Tweak' will have ONE base class, rather than the variety
>>of specific base classes it will need for this use:
>
>which is ok if the instances that we want to tweak are all instances of
the
>same class -- which is a bad assumption in general, so I agree with you:
>the class statement needs to be in the def body (which, to me, decreases
>the attractiveness of that approach compared to the first approach).

But now I'm prepared to flip-flop again because I just discovered that
JPython (which is what I use most of the time) doesn't support the "new"
module -- so the "create a subclass on the fly and change the __class__
attribute of the instance" approach just became a lot more appealing to me.
:-)

In the absence of the "new" module it seems like its either 1) use the
approach above or 2) use the earlier suggestion of "add a method to the
class, retrieve a bound method using the 'dot' syntax, assign that to the
instance, then delete the method from the class".

Jim





More information about the Python-list mailing list