Il 16/11/07, Pietro Battiston<[EMAIL PROTECTED]> ha scritto:

> Grazie mille, in effetti è proprio quello che mi serviva. Ma __new__
> rimpiazza __init__?

No, __new__ che come ti hanno già detto è solo per le classi new style
è chiamato da python stesso quando crei un'istanza della classe,
ovvero se fai

x = Foo(bar=23)

python eseguirà:

x = Foo._ _new_ _(Foo, bar=23)

proseguirà poi eseguendo __init__ con gli stessi argomenti (bar=23)

__new__ è uno static method diversamente da __init__ che è un metodo
dell'istanza x.

Come diceva Facundo, a meno che non hai eigenze molto particolari per
usare __new__ (per il singleton ad esempio) è sempre buona norma usare
solo __init__ che chiamerà __new__ al tuo poto.

ciao
-- 
Gian Mario Tagliaretti
_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Rispondere a