[Tutor] A class that instantiates conditionally ?

Alan Gauld alan.gauld at btinternet.com
Tue Mar 1 18:50:18 CET 2011

"Hugo Arts" <hugo.yoshi at gmail.com> wrote

> Side question: Any reason why you'd raise the exception from __new__
> rather than __init__? If you want to return None, then yeah I can 
> see
> why you'd have to use __new__, but would there be any reason you 
> can't
> or shouldn't simply raise an exception from __init__?

Because by the  time you get to init you have already created
the instance. If you really want to avoid creating an instance it
needs to be in new.

Alan G

More information about the Tutor mailing list