Can a base class know if a method has been overridden?

Stéphane Larouche stephane.larouche at polymtl.ca
Mon Sep 24 13:56:04 EDT 2007


What about something like:

class A(object):
	def my_method(self):
		print "A.my_method"
	def call_my_method(self):
		if type(self).my_method == A.my_method:
			print "Calling base class method."
		else:
			print "Calling derived class method."
		self.my_method()
		
class B(A):
	pass

class C(A):
	def my_method(self):
		print "C.my_method"

a = A()
b = B()
c = C()

a.call_my_method()
b.call_my_method()
c.call_my_method()


Stéphane






More information about the Python-list mailing list