Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52534
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'none:': 0.07; 'constructor': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'constructor.': 0.16; 'ignoring': 0.16; 'message-id:@4ax.com': 0.16; 'out"': 0.16; 'parameters,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:class': 0.16; 'aug': 0.22; 'instance,': 0.24; 'url:home': 0.24; 'question': 0.24; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'parameters.': 0.31; 'skip:_ 10': 0.34; 'basic': 0.35; 'possible.': 0.35; 'but': 0.35; 'are,': 0.36; 'c++': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.36; 'subject:?': 0.36; 'received:76': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'more': 0.64; 'different': 0.65; 'default': 0.69; 'secret': 0.74; 'goal': 0.75; '"leave': 0.84; 'good,': 0.91; '2013': 0.98 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
| Subject | Re: many constructors in a class? |
| Date | Wed, 14 Aug 2013 18:40:50 -0400 |
| Organization | IISS Elusive Unicorn |
| References | <520b913f$0$13995$426a74cc@news.free.fr> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | adsl-76-253-105-23.dsl.klmzmi.sbcglobal.net |
| X-Newsreader | Forte Agent 6.00/32.1186 |
| X-No-Archive | YES |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.589.1376520059.1251.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1376520059 news.xs4all.nl 15891 [2001:888:2000:d::a6]:59796 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:52534 |
Show key headers only | View raw
On 14 Aug 2013 14:16:31 GMT, climb65 <climb65@laposte.net> declaimed the
following:
>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.
>
Well... Secret Python-Fu -- __init__() is NOT a constructor. The
constructor is __new__(); __init__() is just an initializer of whatever
__new__() creates.
Ignoring that detail... NO!
If the goal is to be able to "leave out" some parameters, that is
performed by setting default values for the missing parameters.
def __init__(self, these, are, mandatory, but=None, this=None,
is=None, optional=None):
self.these = these
self.are = are
self.mandatory = mandatory
if but is None:
self.but = these + are
else:
self.but = but
#etc.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
many constructors in a class? climb65 <climb65@laposte.net> - 2013-08-14 14:16 +0000
Re: many constructors in a class? Phil Le Bienheureux <phil.le.bienheureux@gmail.com> - 2013-08-14 16:46 +0200
Re: many constructors in a class? duncan smith <buzzard@invalid.invalid> - 2013-08-14 16:07 +0100
Re: many constructors in a class? Beth McNany <beth.mcnany@gmail.com> - 2013-08-14 10:40 -0400
Re: many constructors in a class? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-14 18:40 -0400
Re: many constructors in a class? Steven D'Aprano <steve@pearwood.info> - 2013-08-15 07:23 +0000
Re: many constructors in a class? Fábio Santos <fabiosantosart@gmail.com> - 2013-08-15 11:09 +0100
Re: many constructors in a class? Roy Smith <roy@panix.com> - 2013-08-15 09:00 -0400
csiph-web