[Tutor] A class that instantiates conditionally ?

Alan Gauld alan.gauld at btinternet.com
Tue Mar 1 17:31:27 CET 2011


"David" <bouncingcats at gmail.com> wrote

> clever enough to refuse to instantiate itself if a necessary 
> condition
> is not met.
>

> class MyClass_2(object):
>     def __new__(self, condition):
>          if condition:
>                return object.__new__(self)
>          else:
>                return None

Thats pretty much how I'd do it.

Alan G. 




More information about the Tutor mailing list