Different methods with same name but different signature?

Justin Sheehy justin at linus.mitre.org
Thu Apr 15 14:54:53 EDT 1999


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





More information about the Python-list mailing list