oop - How to Call Undefined Methods Sequentially in Python Class -
with getattr, can : myclass.method1()
but i'm looking myclass.method1().method2()
or myclass.method1.method2()
.
it means method1
, method2
not defined in class.
is there way call undefined methods sequentially in python class?
i not sure, seems calling undefined method normal method want call name (because can not call not defined).
in case, can nest getattr
many times need go deeper, here example:
class test: def method_test(self): print('test') class another: def __init__(self): self._test = test() def method_another(self): print('another') return self._test = another() getattr( getattr(another, 'method_another')(), 'method_test' )()
the last statement another.method_another().method_test()
.
Comments
Post a Comment