Deleting an object

a) You can create reset() method which sets the object to an initial state. It could be the same as your current __init__() is and you can call it from __init__().

    def __init__(self, uut):     
        self.reset(uut)

    def reset(self, uut):     
        ...

b) Python has garbage collection so when there is no reference to an object, it gets deleted automatically.

a = object()
a = None  # After this command the original object instance is deleted.
del a     # This has the same effect on the object instance when used instead.

del in addition to removing the object reference also removes the variable.


Note that in your inst() method you are always creating a new instance regardless what cls._inst contains.

1 Like