<p dir="ltr">I agree with Steven here.</p>
<p dir="ltr">classmethod is the best practise, most practical, readable, future-proof, one obvious way to do it.</p>
<div class="gmail_quote">On 15 Aug 2013 08:29, "Steven D'Aprano" <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Wed, 14 Aug 2013 14:16:31 +0000, climb65 wrote:<br>
<br>
> Hello,<br>
><br>
> here is a small basic question :<br>
><br>
> Is it possible to have more than one constructor (__init__ function) in<br>
> a class? For instance, to create an object with 2 different ways? If my<br>
> memory is good, I think that with C++ it is possible.<br>
><br>
> Thanks for your answer.<br>
<br>
Yes it is. The built-in type dict is a good example, there is the regular<br>
default constructor[1] that you can call like this:<br>
<br>
dict([('a', 100), ('b', 200)], spam=1, ham=2, eggs=3)<br>
<br>
<br>
Plus there is an alternative constructor that you can call like this:<br>
<br>
dict.fromkeys(['a', 'b', 'spam', 'ham', 'eggs'])<br>
<br>
<br>
The way to create an alternative constructor is to use a class method:<br>
<br>
<br>
def MyDict(dict):<br>
    @classmethod<br>
    def fromkeys(cls, keys):<br>
        ...<br>
<br>
<br>
If you need further details, please ask.<br>
<br>
<br>
<br>
<br>
[1] The constructor is __new__, not __init__. __init__ is called to<br>
initialise the instance after __new__ constructs it.<br>
<br>
<br>
--<br>
Steven<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</blockquote></div>