new.instancemethod

James_Althoff at i2.com James_Althoff at i2.com
Fri May 18 17:48:30 EDT 2001


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).

<snip>

>"Judiciously" is a keyword
>here I think -- it's great for experimental interactive specialized
>programming frameworks, but I can't think of a case I would WANT
>to use such black magic in _production_ code.

Presumably when you say black magic you are referring to the second
approach (changing the __class__ attribute of an instance) and not the
first approach (using "new.instancemethod")?  Because if both, then I'm
back to my original interest of looking for a good example of (needing) and
practice for (implementing) "instance-specific behavior" that would be
reasonable to use -- even in production code.  I believe you are saying
that approach 1 is a reasonable way to go in your experience (if the need
arises such as in your bridge game example).

>
>
>Alex

Jim





More information about the Python-list mailing list