A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/070586.html below:

idioms for abstract base classes

idioms for abstract base classes idioms for abstract base classesRobin Becker robin at jessikat.fsnet.co.uk
Fri Apr 13 10:44:30 EDT 2001
In article <9b6qtv02h2i at news2.newsguy.com>, Alex Martelli
<aleaxit at yahoo.com> writes
>"Robin Becker" <robin at jessikat.fsnet.co.uk> wrote in message
>news:mZW4xJA40t16EwtA at jessikat.fsnet.co.uk...
>> what's the best way to spell an abstract base class so that
>> 0) base is B and A inherits from B
>> 1) doing B() causes an exception
>> 2) most of the initialisation code is common in B
>    [snip]
>> is there a neater way to do this that knows when B is being instantiated
>directly?
>
>Pretty easy:
>
>class B:
>    def __init__(self):
>        if self.__class__ == B:
>            raise AbstractClassException, B
>        # proceed with initialization tasks
>
>self.__class__ is set to the actual (most-derived) class
>that is being instantiated, whether B's __init__ is being
>executed explicitly or through inheritance.
>
>
>Alex
....
yes that's the sort of thing
-- 
Robin Becker

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4