I am reading a code. There is a class in which __del__
method is defined. I figured out that this method is used to destroy an instance of the class. However, I
As mentioned earlier, the __del__
functionality is somewhat unreliable. In cases where it might seem useful, consider using the __enter__
and __exit__
methods instead. This will give a behaviour similar to the with open() as f: pass
syntax used for accessing files. __enter__
is automatically called when entering the scope of with
, while __exit__
is automatically called when exiting it. See this question for more details.