Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103892
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: What arguments are passed to the __new__ method ? |
| Date | 2016-03-02 11:26 -0700 |
| Message-ID | <mailman.109.1456943239.20602.python-list@python.org> (permalink) |
| References | <56d5d043$0$632$426a74cc@news.free.fr> <djoms1F1q2aU2@mid.individual.net> <nb79hd$joh$1@dont-email.me> |
On Wed, Mar 2, 2016 at 10:57 AM, Rob Gaddi <rgaddi@highlandtechnology.invalid> wrote: > Peter Pearson wrote: > >> On Tue, 1 Mar 2016 18:24:12 +0100, ast wrote: >>> >>> It's not clear to me what arguments are passed to the >>> __new__ method. Here is a piece of code: >>> >>> >>> class Premiere: >>> >>> def __new__(cls, price): >>> return object.__new__(cls) >>> >>> def __init__(self, price): >>> pass >> [snip] >> >> Of course, maybe you don't need to define a __new__ method at all. >> Personally, I find that __init__ suffices for my simple needs. >> > > I tend to need __init__ on about half of the classes I write. I think > I've needed __new__ all of twice in the years I've been writing Python. Typically there are only two reasons to override __new__: you potentially want to return an object of a different class than the class that was called, or you're subclassing an immutable type and need to handle the superclass arguments before they get passed to the constructor.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
What arguments are passed to the __new__ method ? "ast" <nomail@invalid.com> - 2016-03-01 18:24 +0100
Re: What arguments are passed to the __new__ method ? eryk sun <eryksun@gmail.com> - 2016-03-01 13:54 -0600
Re: What arguments are passed to the __new__ method ? Terry Reedy <tjreedy@udel.edu> - 2016-03-01 15:27 -0500
Re: What arguments are passed to the __new__ method ? eryk sun <eryksun@gmail.com> - 2016-03-01 15:09 -0600
Re: What arguments are passed to the __new__ method ? "ast" <nomail@invalid.com> - 2016-03-02 10:23 +0100
Re: What arguments are passed to the __new__ method ? Steven D'Aprano <steve@pearwood.info> - 2016-03-02 22:02 +1100
Re: What arguments are passed to the __new__ method ? Peter Pearson <pkpearson@nowhere.invalid> - 2016-03-02 17:40 +0000
Re: What arguments are passed to the __new__ method ? Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-03-02 17:57 +0000
Re: What arguments are passed to the __new__ method ? Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-02 11:26 -0700
csiph-web