I have a superclass that has a lot of arguments. I want to create a subclass that shares all of those arguments and adds additional one or two arguments. To ommit double-coding, I used a method specified in Avoid specifying all arguments in a subclass :
class Container(Item):
def __init__(self,**kwargs):
try: self.is_locked=kwargs.pop('is_locked')
except KeyError: pass
super(Container, self).__init__(**kwargs)
def open(self):
print "aw ys"
However, when I then try to call an object of a Container class:
> some_container.open()
AttributeError: 'Item' object has no attribute 'open'
It appears as if the some_container is not a Container() but rather an Item() with a single variable is_locked added. What am I doing wrong?
edit: My Item definition:
class Item(object:
def __init__(self,istemplate,id,short,long,type,flags,value,damagerange,damagereductionrange,weight):
if istemplate==False:
self.__class__.instances.append(self)
self.istemplate=istemplate
(... many variables like that...)
self.id=id
self.randomizestuff()
if istemplate==True:
self.__class__.templates.append(copy.deepcopy(self))