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

Java has try-with-resources for this. Python has with. Unlike say C++ you do have to indent your code once for every such resource though which can be cumbersome.


Neither of these things are equivalent to destructors, however


They aren't equivalent but they can do the task in question:

   with prompt_password() as password:
     stuff
Once the scope exits, the context manager can scramble the memory.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: