"implemented by subclass"

Paul Rubin phr-n2002a at nightsong.com
Sat Feb 16 18:03:36 EST 2002


philh at comuno.freeserve.co.uk (phil hunt) writes:
> Consider the following python code:
> 
> class Log:
>    def write(self, text): 
>       """(implemented by subclass)"""  
> 
> 
> Is this the most pythonic way to do it? If not, what would be
> better? How about rasing a ShouldBeImplementedBySublass exception?
> 
> How do other people do it?

    def write(self,text):
       raise NotImplementedError


Description of NotImplementedError from "built-in exceptions" section
of library doc:

    exception NotImplementedError

    This exception is derived from RuntimeError. In user defined base
    classes, abstract methods should raise this exception when they
    require derived classes to override the method. New in version 1.5.2.



More information about the Python-list mailing list