I have class A
that is supposed to inherit class B
whose name is not yet known at the time of A
being written. Is it possible to declare A
not inheriting anything, and add B
as the base class during A
's instantiation? Example:
First file
class B:
def __init__(self):
self.__name = "Class B"
def name(self):
return self.__name
Second file
class A:
def __init__(self):
self.__name = "Class A"
# At some point here, the appropriate module name and location is discovered
import sys
sys.path.append(CustomModulePath)
B = __import__(CustomModuleName)
magic(A, B) # TODO What should magic() do?
a = A()
print a.name() # This will now print "Class A", since name() is defined in B.