Function Overloading and Python
Stefan Behnel
stefan_ml at behnel.de
Mon Feb 25 02:44:36 EST 2008
Allen Peloquin wrote:
> class B
> {
> fun(A x, A y, A z)...
> fun(A1 x, A y, A z)...
> }
>
> class B1
> {
> fun(A1 x, A y, A z)...
> }
>
> Such that any previous behavior is inherited, but behaves
> polymorphically because of the single function name.
Try something like this:
class B(object):
def fun(x,y,z):
if isinstance(x, A1):
return self._fun(x,y,z)
# ...
def _fun(x,y,z):
# ...
class B1(B):
def _fun(x,y,z):
# ...
Stefan
More information about the Python-list
mailing list