callable virtual method

Christian Heimes lists at cheimes.de
Sat Aug 15 00:25:00 CEST 2009


Jean-Michel Pichavant wrote:
> talking about approaches:
> 
> 1/
> class Interface:
>     def foo(self):
>        if self.__class__.foo == Interface.foo:
>           raise NotImplementedError
> 
> 2/
> class Interface:
>     def foo(self):
>        self._foo()
> 
>     def _foo(sef):
>        raise NotImplementedError

Please don't call it an interface when it's really an abstract base 
class. And abstract base classes are probably the solution the OP is 
looking for, http://docs.python.org/library/abc.html

Christian




More information about the Python-list mailing list