self deleting instance

python

Solution

I need do something like this to be sure that will never exist a kind of instance.

If you simply want to prevent the creation of such an instance, raise an exception in `__init__()` whenever the condition is satisfied.

This is standard protocol for signalling constructor failures. For further discussion, see Python: is it bad form to raise exceptions within __init__?

Problem

Is it possible to make a class call `del()` for some instances under some condition? Or turn self into None? ``` class T: def __init__(self, arg1, arg2): condition=check_condition(arg1,arg2) if not condition: do_something(arg1) else: del(self) #or self=None or return None ``` I need to do something like this to be sure that will never exist a kind of instance.

Original source

Related problems