[SciPy-user] mandatory overriding of class method

Fernando Perez Fernando.Perez at colorado.edu
Mon Jul 18 15:32:14 CDT 2005

Ryan Krauss wrote:
> I have a general Python question (but I am not subscribed to a general 
> Python list:)-  I intend to use this for technical computing if that 
> makes it any better.
> I want to define a class that I don't the user to be able to use 
> directly and I want to require the user to derive from the class and I 
> want to require that two specifics methods be overridden for the derived 
> class to be valid.  I think in C++ you could define virtual methods so 
> that they had to be overridden.  Is there a way to do this in Python?  I 
> thought about defining the two methods in the base class to do nothing 
> but raise exceptions, but that is kind of a hack and the user would know 
> there was a problem until they tried to call the methods.

standard idiom:

class foo:
   def something(self):
     raise NotImplementedError



More information about the SciPy-user mailing list