Swapping superclass from a module

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun May 17 03:37:45 CEST 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".





More information about the Python-list mailing list