Swapping superclass from a module

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat May 16 21:37:45 EDT 2009


On Sat, 16 May 2009 09:55:39 -0700, Emanuele D'Arrigo wrote:

> Hi everybody,
> 
> let's assume I have a module with loads of classes inheriting from one
> class, from the same module, i.e.:
[...]
> Now, let's also assume that myFile.py cannot be changed or it's
> impractical to do so. Is there a way to replace the SuperClass at
> runtime, so that when I instantiate one of the subclasses NewSuperClass
> is used instead of the original SuperClass provided by the first module
> module?

That's called "monkey patching" or "duck punching".

http://en.wikipedia.org/wiki/Monkey_patch

http://wiki.zope.org/zope2/MonkeyPatch

http://everything2.com/title/monkey%2520patch



-- 
Steven



More information about the Python-list mailing list