Movatterモバイル変換
[0]ホーム
Newbie inheritance problem
zzzzzzzizz_ at notmail.com
Mon Apr 2 07:36:45 EDT 2001
Hi all, I have overwridden the __add__ method for a class, then builta class based on the above class; however, the object I'm returning isof the base class not the inherited class. If that doesn't make sensesee below:class A: def __init__(self,value=0.0) self._value=float(value) def __add__(self,other) return A(self._value+other._value)class B(A): passx=B(3)y=B(2)z=x+yThe way I've done it z becomes an instance of A not B!!! How do I doit correctly? Do I have to override all the __add__, __sub__, etc...methods?
More information about the Python-listmailing list
[8]ページ先頭