의 우리가이 수업을 가정 해 봅시다 :부모로부터 속성을 얻는 방법?
class Foo(object):
_bar = ""
def __init__(self):
self.bar = "hello"
def getBar(self):
return self._bar
def setBar(self, bar):
self._bar = bar
def getAttributes(self):
for attr in self.__dict__:
print attr
bar = property(getBar, setBar)
class Child(Foo):
def __init__(self):
super(Child, self).__init__()
self.a = ""
self.b = ""
을 내가 좋아하는 뭔가를 할 경우 :
child = Child()
child.getAttributes()
내가 부모와 자식의 모든 특성을 얻을. 부모로부터 속성을 어떻게 얻을 수 있습니까?
미리 감사드립니다.
자식을 통해 Foo 클래스의 getAttributes를 호출하려고합니까 ?? –
'Foo.getAttributes()'를 호출하지 않는 이유는 무엇입니까? – John
예입니다. 제 실제 프로그램에서는 많은 수업이 주 수업에서 연장됩니다.이러한 클래스의 변수 목록이 있지만 부모로부터 속성에 액세스하고 싶습니다. 그래서 예를 들어 getAttributes를 호출합니다. 어떤 클래스인지 모르겠습니다. – bribon