Python __enter__ / __exit__ vs __init__ (or __new__) / __del__
问题 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__ ?) / __del__ . I understand that __enter__ / __exit__ are intended for use with the with statement as context managers, and the with statement is great. But the counterpart to that is that any code in those blocks is only executed in that context. By using these instead of __init__ / __del__ I appear to be creating an implicit contract with callers that they