[Tutor] Dynamic inheritance?
kent37 at tds.net
Sat Nov 19 18:53:11 CET 2005
Jan Eden wrote:
> I have a number of classes, each of which should inherit from a
> related superclass in another module:
> class A(Super.A): ...
> class B(Super.B): ...
> class C(Super.C): ...
> Is there a way to dynamically determine the value of Super at
> runtime? Background: Depending on certain object attributes which are
> set during the object initialization, I need to use a different set
> of templates for the respective object.
Sure, just import the correct template module conditionally and give it a new name:
if site == 'siteA':
import SiteA as Super
import SiteB as Super
If you need to do the import based on a string use the __import__() function:
> The problem is that the template classes are not self contained, i.e.
> SiteB.Gallery inherits from SiteB.List, SiteB.Base etc.>
> Thanks in advance,
I don't see why that is a problem?
More information about the Tutor