Capisco come funzionano entrambe le funzioni __init__
e __new__
. Mi chiedo se non c'è nulla che lo può fare che lo __new__
non può?Python: usa sempre __new__ invece di __init__?
cioè può usare di __init__
è sostituito dal seguente schema:
class MySubclass(object):
def __new__(cls, *args, **kwargs):
self = super(MySubclass, cls).__new__(cls, *args, **kwargs)
// Do __init__ stuff here
return self
sto chiedendo come mi piacerebbe fare questo aspetto della Python OO adattarsi meglio nella mia testa.
possibile duplicato di [perché definito '\ _ \ _ new__' e '\ _ \ _ init__' tutto in una classe] (http: // stackoverflow.it/questions/2017876/why-defined-new-and-init-all-in-a-class) –
Vecchia domanda su questo argomento: [L'uso di Python di \ _ \ _ new__ e \ _ \ _ init__?] (http://stackoverflow.com/questions/674304/pythons-use-of-new-and-init) –