Pure virtual functions in Python?

I V ivlenin at gmail.com
Sat Feb 20 21:04:21 CET 2010


On Sat, 20 Feb 2010 08:12:01 -0800, lallous wrote:
> How can I do something similar to pure virtual functions in C++ ?

>From what you want, it seems like you want cb() to not be called if it 
isn't implemented in the derived class; this isn't really what pure 
virtual functions in C++ do - pure virtual functions enforce, at compile 
time, that the derived class implements the method.

If you have a situation when you want to either call a derived class's 
version of cb(), or do nothing, can you not just have an implementation 
of cb() in the base class that does nothing, i.e.

class C1(object):
	def cb(self, param1, param2):
		pass



More information about the Python-list mailing list