[Tutor] Re: Re: Factory classes (etc)

Emile van Sebille emile@fenx.com
Wed, 4 Sep 2002 08:09:32 -0700


Erik
> Python doesn't let you do method overloading?  On second thought, that
> makes sense since it's not strictly typed (how is Python going to know
> the difference between Constructor(String a, int b) and
Constructor(int
> a, String b)).  I hadn't considered this before.
>

Python isn't going to do it for you, but you can.

def test(a,b):
    try: return a*1., b+""
    except:
        try: return a+"", b*1.
        except:
            raise 'invalid args'

test() accepts string,int or int,string, or any pair that allows for
floating point multiplication and string addition.

--

Emile van Sebille
emile@fenx.com

---------