Utile per
__getattr__
e __getattribute__
object.__getattr__(self, name)
restituisce il valore dell’attributo di nome name o lancia un’eccezione AttributeErrorobject.__getattribute__(self, name)
__getattr__()
allora quest’ultimo metodo viene invocato nel caso in cui __getattribute__()
lo invochi esplicitamente o lanci un’eccezione AttributeError__getattribute__()
deve restituire il valore dell’attributo o lanciare un’eccezione AttributeError__getattribute__()
deve sempre invocare il metodo della classe base usando lo stesso nome per evitare la ricorsione infinita__getattribute__()
di object occorre scrivere object.__getattribute__(self, name)
__new__
e __init__
__new__
crea un oggetto__init__
inizializza le variabili dell’istanza__new__
e poi __init__