From: justin at linus.mitre.org (Justin Sheehy)
Date: 15 Apr 1999 14:54:53 -0400
Subject: Different methods with same name but different signature?
References: <3716909C.D8D1B372@fedex.com>
Message-ID: <glmsoa1g1du.fsf@caffeine.mitre.org>
X-UID: 1597                                                  

frederic pinel <fpinel at fedex.com> writes:

> My class needs to have 2 (or more) different methods, but with the same
> name, the difference being the signature (an object in my case),

Since you don't need to specify argument types in Python function
definitions, what you describe is not reasonably possible.  Python
functions do not have signatures in the way that a C++ programmer
means that term.  In any case, I'd be willing to bet that you don't
really need to have multiple functions with one name.

You can simply make one function of that name, and have it branch or
otherwise act appropriately based on the argument types.  Not only is
this nicer than the C++ way, it will probably be easier for someone
else to understand when they read your code.

I'll take Python's flavor of polymorphism over C++'s any day.  No contest.

-Justin





