I have searched and I\'m unable to come up with any good reason to use python\'s __enter__ /__exit__ rather than __init__ (or __new_
__enter__
__exit__
__init__
__new_
del x doesn’t directly call x.__del__()
del x
x.__del__()
You have no control over when .__del__ is called, or in fact whether it gets called at all.
.__del__
Therefore, using __init__/__del__ for context management is not reliable.
__del__