할 수도 하위 클래스 list
이 경우 처리하기 위해이 당신이 무엇을 얻을
class Test:
_instances = customList()
def __init__(self, arg=0):
self._instances.append(self)
self.nb = arg
def incr(self, arg):
self.nb += arg
def get_nb(self):
return self.nb
@classmethod
def get_instances(cls):
return cls._instances
: 그리고 여기
class customList(list):
def __getattribute__(self, attr):
try:
return super(customList, self).__getattribute__(attr)
except AttributeError:
method_list = [getattr(el, attr) for el in self]
def call_me(*args, **kwargs):
return [method(*args, **kwargs) for method in method_list]
return call_me
는 테스트 클래스를
>>> a = Test(0)
>>> b = Test(1)
>>> c = Test(2)
>>> instances = Test.get_instances()
>>> instances.incr(3)
[None, None, None]
>>> instances.get_nb()
[3, 4, 5]
이러한 메서드 호출의 * 반환 값 *을 갖고 싶습니까? 또는 rv가 삭제 되었습니까? –