darkgaze darkgaze - 1 year ago 80
Python Question

Know if child class has implemented a parent method

I have a base class class X, and a child class Y which could reimplement or not a method from the base class X.

I pass the name of the child class as a variable to functions.

Inside those functions I need to test if that class passed has implemented or not some methods from it's base class.

(I can't use hasattr(childClassName.methodName) since it always returns True)

Answer Source

use to compare:

 getattr(className, 'methodName') is getattr(className, 'method')

if false, the method was overridden

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download