No method overloading

MeTheGameMakingGuy gopsychonauts at
Sun Aug 24 10:18:31 CEST 2008

On Aug 24, 6:15 pm, Hussein B <hubaghd... at> wrote:
> Hey,
> Please correct me if I'm wrong but Python doesn't support method
> overload, right?
> --
> def method(self):
>  #code
> def method(self, data):
>  #code
> --
> The last declaration of method() erase the previous one (like
> JavaScript).
> Thanks.

Correct. The second declaration overwrites the first. Give data a
default argument instead:
def method(self, data=None):
 if data is None:
  # Normal code
  # data included code

Not sure how Pythonic that is, but it should work the way you're
requesting... I think.

More information about the Python-list mailing list