чтоо?) поясни
Yes, use getattr() to get the attribute, and callable() to verify it is a method: invert_op = getattr(self, "invert_op", None) if callable(invert_op): invert_op(self.path.parent_op)
Как проверить наличие метода в объекте класса?
or this , if U like Lambdachka has_op = lambda obj, op: callable(getattr(obj, op, None))
Спасибо
вот Топчик решение! from inspect import ismethod def method_exists(instance, method): return hasattr(instance, method) and ismethod(getattr(instance, method))
Мне просто нужно узнать, есть ли метод в обьекте
if hasattr(instance, method) and ismethod(getattr(instance, method))
Обсуждают сегодня