3 ms·
It's not the same thing at all because you have to remember to use the context manager, while in C++ the user doesn't need to write any extra code to use the de
by logicchains 10mo ago
It's not the same thing at all because you have to remember to use the context manager, while in C++ the user doesn't need to write any extra code to use the destructor, it just happens automatically.
- kibwen 10mo agoTo be fair, that's just an artifact Python's chosen design. A different language could make it so that acquiring the object whose context is being managed could require one to use the context manager. For example, in Python terms, imagine if `with open("foo") as f:` was the only way to call `open`, and gave an error if you just called it on its own.