No method overloading
Fredrik Lundh
fredrik at pythonware.com
Sun Aug 24 04:25:07 EDT 2008
Hussein B wrote:
> 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).
in Python, methods are callable attributes, and an attribute can only
have one value. you can use default arguments to work around this:
def method(self, data=None):
if data is None:
#code
else:
#code
</F>
More information about the Python-list
mailing list