Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52548
| From | Roy Smith <roy@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: many constructors in a class? |
| Date | 2013-08-15 09:00 -0400 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <roy-0FD4AE.09002715082013@news.panix.com> (permalink) |
| References | <520b913f$0$13995$426a74cc@news.free.fr> <520c81f6$0$29885$c3e8da3$5496439d@news.astraweb.com> |
In article <520c81f6$0$29885$c3e8da3$5496439d@news.astraweb.com>, Steven D'Aprano <steve@pearwood.info> wrote: > [1] The constructor is __new__, not __init__. __init__ is called to > initialise the instance after __new__ constructs it. True, but be warned that writing your own __new__() is quite rare and probably falls into the realm of dark magic. If you're just starting out, learn about __init__(), and don't worry about __new__() at all. For those of you coming from a C++ background, Python's __init__() is like C++'s constructor, and __new__() is more like operator new. That's not a perfect analogy from a functional standpoint, but it's a good guide for how often you'll want to write each one. And then, of course, there's __enter__() and __exit__(), which are like C++'s constructor and destructor, but that's another story :-)
Back to comp.lang.python | Previous | Next — Previous 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