Python Polymorphism

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Thu May 12 16:17:23 EDT 2005


Carlos Moreira wrote:

> So, let's try again.
> Supose that I want to create two methos (inside a
> class) with exactly same name, but number of
> parameters different:
> 
> class myClass:
>      myAttribute = 0
>      def myMethod(self):
>           self.myAttribute += 1
>      def myMethod(self, myValue):
>           self.myAttribute += myValue
> 
> Both method hold same identifier, the only difference
> in them signture are parameters.
> How could I simulate the situation above, using the
> language dynamic link (or polymorphism, as you
> prefer)?

Ah, that's not polymorphism; it's method overloading. And AFAIK it is 
not possible in Python.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven



More information about the Python-list mailing list