I am trying to make a subclass from a class with a @classmethod defined:
class Pet(object):
def __init__(self,animal):
self.animal = animal
@classmethod
def wild(cls,animal):
return cls('wild '+animal)
class Cat(Pet):
def __init__(self):
Pet.wild('cat')
if __name__ == '__main__':
print Cat().animal
This gives me the following error:
print Cat().animal
AttributeError: Cat instance has no attribute 'animal'
Probably I don't fully understand the concept of subclassing, I have been also trying to pass self
to Pet.wild
without much more success. Any help would be really appreciated!
EDIT
I try to explain what I want to do: I would like to initialize parentclass (or superclass?) Pet
from the Cat
subclass using the classmethod wild
and not using __init__
. Is this possible? Thank you