Python __enter__ / __exit__ vs __init__ (or __new__) / __del__
There are several differences you appear to have missed: Context manager get a chance to provide a new object just for the block you are executing. Some context managers just return self there (like file objects do), but, as an example, database connection objects could return a cursor object tied to the current transaction. Context … Read more