Swapping superclass from a module

Emanuele D'Arrigo manu3d at gmail.com
Sat May 16 12:55:39 EDT 2009


Hi everybody,

let's assume I have a module with loads of classes inheriting from one
class, from the same module, i.e.:

## myFile.py
class SuperClass(object)
class SubClass1(SuperClass)
class SubClass2(SuperClass)
class SubClass3(SuperClass)

In a separate file I also have:

## myOtherFile.py
class NewSuperClass(object)

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 was the generic case. Would the solution change much if
NewSuperClass was actually inheriting from SuperClass, effectively
wedging itself between the SuperClass and the SubClasses?

Manu






More information about the Python-list mailing list