What arguments are passed to the __new__ method ?

ast nomail at invalid.com
Tue Mar 1 12:24:12 EST 2016


Hello

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

p = Premiere(1000)

No errors, so it seems that 2 arguments are passed
to __new__, cls and price.


But if i do:


class Premiere:

    def __new__(cls, price):
        return object.__new__(cls, price)

    def __init__(self, price):
        pass

p = Premiere(1000)


it fails. It is strange because according to me it is equivalent to:


class Premiere:

    def __init__(self, price):
         pass

p = Premiere(1000)


which is OK.







More information about the Python-list mailing list