(Newbie) Restricting inherited methods to operate on element from same subclass
andy2O at hotmail.com
andy2O at hotmail.com
Fri Mar 11 08:26:34 EST 2005
>Assuming that A is a new-style class then if they have to be
>exactly the same type compare the types
Ah-ha! I didn't know that.
>if the 'other' value can be a subclass of self:
>
> def join(self, other):
> if not isinstance(other, type(self)):
> raise whatever
Simple and neat!
>If A is an old-style class then you would have to compare
>the __class__ attribute: self.__class__ != other.__class__
That answered my question perfectly. I'll read up on the new style
classes and pick whichever of your solutions fits best.
Many thanks,
Andy.
More information about the Python-list
mailing list