Different methods with same name but different signature?

frederic pinel fpinel at fedex.com
Thu Apr 15 21:21:32 EDT 1999


Hello,

While trying to implement the visitor pattern in Python, I ran into the
following problem:

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),
unfortunately Pyhton interprets this as an overidding, and only
considers the last method defined.
C++ being able to switch to the right method, based on the signature, I
thought Python would.

Being new to Python, is this a limitation or am I missing something?
(Python being great I suspect -and hope- it's my ignorance!)

Any help would be great!

PS: as a workaround, I tried:
- using a single method, but checking isinstance() of the object passed
to switch to the right code,
- using different names for the methods,
which both work.

regards,
frederic




More information about the Python-list mailing list