Steven Bethard wrote:
> So even though your __new__ method returns the object you want, the
> __init__ method is clearing out all the items you've added and then
> re-adding them as it normally would. To prove this to yourself, take a
> look at what happens when we override __init__::
>
Okay,
Ken Schutte wrote:
> Steven Bethard wrote:
>>
>> The __new__ method is for immutable types. So things like str and int
>> do their initialization in __new__. But for regular mutable types,
>> you should do your initialization in __init__::
>
> I see... So, is there a use for __new__ in mutable
Ken Schutte <[EMAIL PROTECTED]> wrote:
> Steven Bethard wrote:
> >
> > The __new__ method is for immutable types. So things like str and int
> > do their initialization in __new__. But for regular mutable types, you
> > should do your initialization in __init__::
>
> I see... So, is there a us
Steven Bethard wrote:
>
> The __new__ method is for immutable types. So things like str and int
> do their initialization in __new__. But for regular mutable types, you
> should do your initialization in __init__::
>
I see... So, is there a use for __new__ in mutable types? From my
list-d
Ken Schutte wrote:
> I want an int-derived class that is initilized to one greater than what
> it's constructor is given:
>
> class myint(int):
> def __new__(cls, intIn):
> newint = int(intIn+1)
> return int.__new__(cls, newint)
Or simply:
class myint(int):
def __new__(cls, int_i