On Sat, 25 Feb 2017 05:40 am, MRAB wrote:
>> class Base:
>> def __init__(self):
>> if type(self) is Base:
>> raise TypeError("cannot instantiate Base class")
>>
>>
>> Does that help?
>>
> D'oh! Never thought of that! :-)
>
> The OP is using Python 2.7, so you'll need to use new-style classes:
>
> class Base(object):
> def __init__(self):
> if type(self) is Base:
> raise TypeError("cannot instantiate Base class")
For "classic classes", you can use this:
if self.__class__ is Base:
raise TypeError("cannot instantiate Base class")
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
--
https://mail.python.org/mailman/listinfo/python-list