Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.109.133.86.MISMATCH!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.058 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; '__init__': 0.09; 'constructor': 0.09; 'function,': 0.09; 'def': 0.12; 'afterwards': 0.16; 'subject:class': 0.16; '\xa0\xa0\xa0\xa0\xa0\xa0': 0.16; 'variable': 0.18; 'code,': 0.22; 'memory': 0.22; 'instance,': 0.24; 'question': 0.24; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'url:python': 0.33; 'basic': 0.35; 'possible.': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'c++': 0.36; 'url:listinfo': 0.36; 'thanks': 0.36; 'possible': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'name': 0.63; 'more': 0.64; 'different': 0.65; 'here': 0.66; 'answer.': 0.68; 'default': 0.69; 'good,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=h5WZZtad70yN3yJAotlHPyTXgKxmTekGe8u5dSAXnwY=; b=JhIOMa1KWl7qc2aub9CjJJfWT/P3gsQuk5Kcefo5Etjv+xIfc5g8WcujNqyJ+Z0oTt NK4TG+MNDXrHxzE274PdIoLnFFfOSmT+0ACSV+vA80hfAxMSiRYaD71PuVUV1pRmXFVG QbyRrGW5cDz4agLyeAnDR2LD2+Q5Oli/+MATjUbyldqtKQVg0+7s99sbA3HExuevti5V eRHwwbb7ge4S7tNJ4wiQCD8xXfBzK4nrCRp+LBo8OU60+C2vbFKm5qE5n1Fgq3pfHSDd UtoN2xGe2e18QHEE1nfF6TAaLqFFtOW5y/xESEHZAPVPjN4o+M28DqhoS57wuU1WH2G4 2lYw== MIME-Version: 1.0 X-Received: by 10.66.170.138 with SMTP id am10mr10125307pac.51.1376491593217; Wed, 14 Aug 2013 07:46:33 -0700 (PDT) In-Reply-To: <520b913f$0$13995$426a74cc@news.free.fr> References: <520b913f$0$13995$426a74cc@news.free.fr> Date: Wed, 14 Aug 2013 16:46:33 +0200 Subject: Re: many constructors in a class? From: Phil Le Bienheureux To: python-list@python.org Content-Type: multipart/alternative; boundary=047d7bb0500073411b04e3e96c6a X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 67 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376491598 news.xs4all.nl 15964 [2001:888:2000:d::a6]:46514 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52520 --047d7bb0500073411b04e3e96c6a Content-Type: text/plain; charset=ISO-8859-1 2013/8/14 climb65 > Hello, > > here is a small basic question : > > Is it possible to have more than one constructor (__init__ function) in a > class? For instance, to create an object with 2 different ways? If my > memory is good, I think that with C++ it is possible. > > Thanks for your answer. > -- > http://mail.python.org/mailman/listinfo/python-list > Hello, You have to use default values in __init__ function, like : def __init__( self, name = None ): self.name_ = name and afterwards in your code, test variable : if self.name_: do something... Regards, Phil. --047d7bb0500073411b04e3e96c6a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
=A0
2013/8/14 climb65 <climb65@laposte.net&g= t;
Hello,

here is a small basic q= uestion :

Is it possible to have more than one constructor (__init__= function) in a
class? For instance, to create an object with 2 different ways? If my
me= mory is good, I think that with C++ it is possible.

Thanks for your = answer.
--
http://mail.python.or= g/mailman/listinfo/python-list

=A0
=A0
Hello,
=A0
You have to use default values in __init__ function, like :
def __init__( self, name =3D None ):
=A0=A0=A0=A0=A0=A0=A0 self.name_ =3D name
=A0
and afterwards in your code, test variable :
if self.name_:
=A0=A0=A0=A0=A0=A0 do something...
=A0
Regards,
Phil.
--047d7bb0500073411b04e3e96c6a--