I have a base class like the following:
class Base(object):
def __init__(self, arg1, arg2):
#Declare self
self.arg1 = arg1
self.arg2 = arg2
@classmethod
def from_ini_file(cls, f):
# Get arg1 and arg2 from ini file
return cls(arg1, arg2)
And then I want to be able to use the classmethod constructor in a derived class. Naively, I tried:
class Derived(Base):
def __init__(self):
f = 'default.ini'
Base.from_ini_file(f)
But this doesn't work. I think I understand why this doesn't work, but I haven't been able to figure out how to do this correctly, if it's possible.
Thanks for any and all help.
Edit
This feels very inelegant but I'm currently going with:
class Derived(Base):
def __init__(self):
t = Base.from_ini_file('default.ini')
Base.__init__(t.arg1, t.arg2)
There's a lot of redundant operations here, and I don't like having to have the arguments of the Base.init function be something that necessarily gets saved to the object for use in this way. So I'm all ears for better solutions. Thanks again.