Я пытаюсь написать простую установку, чтобы вызвать родительский класс @classmethod, но получить ошибку ... Пожалуйста, дайте мне знать, в чем проблема?Метод родительского класса
class Parent(object):
def __init__(self):
print "Parent initialized"
@classmethod
def resource_setup(cls):
print "parent method"
class Child(Parent):
def __init__(self):
print "Child initialized"
@classmethod
def childmethod(cls):
super(Parent, cls).resource_setup()
print "child method"
c = Child()
Child().childmethod()
Выход:
Child initialized
Child initialized
Traceback (most recent call last):
File "C:\Users\ANAND\workspace\Scratch\Scratch\Parent.py", line 30, in <module>
Child().childmethod()
File "C:\Users\ANAND\workspace\Scratch\Scratch\Parent.py", line 25, in childmethod
super(Parent, cls).resource_setup()
AttributeError: 'super' object has no attribute 'resource_setup'
Вопрос:
1. When I create a child object c = Child(), I don't see the display of "parent initialized"..I expect the Parent class to be initialized.
2.How can I call the parent method @classmethod from the child @classmethod?