Is this Pythonic?
phil hunt
zen19725 at zen.co.uk
Mon Aug 1 14:15:16 EDT 2005
On Mon, 01 Aug 2005 12:52:02 -0400, Peter Hansen <peter at engcorp.com> wrote:
>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.
Ta
--
Email: zen19725 at zen dot co dot uk
More information about the Python-list
mailing list