<div>Thank you for the explanation.  With my background in Java, I have to get myself to think a little differently.<br clear="all"></div>
<div>Kevin<br><br><br></div>
<div class="gmail_quote">On Tue, Jan 20, 2009 at 1:41 PM, Chris Rebert <span dir="ltr"><<a href="mailto:clp2@rebertia.com">clp2@rebertia.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div class="Ih2E3d">On Tue, Jan 20, 2009 at 10:18 AM, MRAB <<a href="mailto:google@mrabarnett.plus.com">google@mrabarnett.plus.com</a>> wrote:<br>> K-Dawg wrote:<br>>><br>>> Can you overload methods in Python?<br>
>><br>>> Can I have multiple __inits__ with different parameters passed in?<br>>><br>> Simple answer: no.<br><br></div>More complicated answer: Yes, with some caveats.<br><br>You usually don't need to overload methods in Python since you can use<br>
default and keyword arguments instead. For instance:<br><br>class Foo(object):<br>   def __init__(self, a, b=10, c=None):<br>       self.a = a<br>       self.b = b<br>       if c is None: c = []<br>       self.c = c<br><br>
#example use<br>x = Foo("#", 4, [6,7])<br>y = Foo("@")<br>z = Foo("!", c=[1,2])<br><br>Whereas in Java or C++ this would require several overloads, it can be<br>succinctly expressed as a single method in Python.<br>
<br>However, if you want the overloads to accept completely different<br>types as parameters, then it arguably should expressed as distinct<br>methods rather than "overloads". In the special case of __init__, you<br>
might want to make the alternate initializers classmethods or factory<br>functions.<br><br>Cheers,<br>Chris<br><font color="#888888"><br>--<br>Follow the path of the Iguana...<br><a href="http://rebertia.com/" target="_blank">http://rebertia.com</a><br>
</font>
<div>
<div></div>
<div class="Wj3C7c">--<br><a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br></div></div></blockquote></div><br>