Hacker News new | past | comments | ask | show | jobs | submit login

I'd argue the context manager concept is better than destructors, because it's more explicit.

BTW, Python does have the `__del__` special method. It's just that almost all usage of it would be better implemented via context manager.




I think the idiomatic way is with weakref https://docs.python.org/3/library/weakref.html

Particularly note "finalize provides a straight forward way to register a cleanup function to be called when an object is garbage collected"




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: