Signature-based Function Overloading in Python
Daniel Fetchinson
fetchinson at googlemail.com
Tue Feb 23 13:49:53 EST 2010
> In Java, Method Overloading is my best friend, but this won't work in
> Python:
>
> >>> def a():
> pass
> >>> def a(x):
> pass
> >>> a()
> Traceback (most recent call last):
> File "<pyshell#12>", line 1, in <module>
> a()
> TypeError: a() takes exactly 1 argument (0 given)
>
> So - What would be the most pythonic way to emulate this?
> Is there any better Idom than:
>
> >>> def a(x=None):
> if x is None:
> pass
> else:
> pass
This is generally considered to be the pythonic idiom for what you describe.
Cheers,
Daniel
--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
More information about the Python-list
mailing list