Signature-based Function Overloading in Python
jeanmichel at sequans.com
Wed Feb 24 11:28:13 CET 2010
Michael Rudolf wrote:
> Just a quick question about what would be the most pythonic approach
> in this.
> In Java, Method Overloading is my best friend, but this won't work in
> >>> def a():
> >>> def a(x):
> >>> a()
> Traceback (most recent call last):
> File "<pyshell#12>", line 1, in <module>
> 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:
This is the way to do it python, and it has its advantages: 1 docstring,
1 way do do it, 1 interface.
More information about the Python-list