Is this Pythonic?

Peter Hansen peter at engcorp.com
Mon Aug 1 18:52:02 CEST 2005


phil hunt wrote:
> Suppose I'm writing an abstract superclass which will have some 
> concrete subclasses. I want to signal in my code that the subclasses 
> will implement certan methods. Is this a Pythonic way of doing what 
> I have in mind:
> 
> class Foo: # abstract superclass
>    def bar(self):
>       raise Exception, "Implemented by subclass"
>    def baz(self):
>       raise Exception, "Implemented by subclass"

Change those to "raise NotImplementedError('blah')" instead and you'll 
be taking the more idiomatic approach.

-Peter



More information about the Python-list mailing list