Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


To 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: