Function override?

David C. Ullrich ullrich at math.okstate.edu
Fri Mar 31 11:51:48 EST 2000


    I was surprised to see the other two replies didn't say what
I would have said, so maybe what I would have said is "wrong":

    One thing that makes Python more fun than C is that the
variables are typeless (their values have types). So you can
use just one function:

class over:
    def somefun(self, bakeThing):
        if type(bakeThing) == type(1):
            #do the int thing
        elif type(bakeThing) == type(''):
            #do the string thing

    This is certainly one of the things that _I_ find keen,
amyway - I hope the people who are talking about adding
stricter typing to Python make it optional somehow. There
are obvious advantages to stricter typing but you lose
something as well. (For example, I get a big kick out of
the fact that exactly the  same euclidean-algorithm code
works to find the GCD of two integers or the GCD of
two polynomials. Etc.)

"Arinté" wrote:

> I have a class similar to this:
>
> class over:
>    somefun(self, bakeint):
>       ...
>    somefun(self, bakeStr):
>
> If the user uses a string then I want to use the 2nd one, else an
> Integer then use the 1st one?
>
> How can I get this?  And what is this call in c, the word escapes me
> right now.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




More information about the Python-list mailing list