3 ms·
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 th
by xapata 6y ago
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.
- bobbyi_settv 6y agoI think the idiomatic way is with weakref https://docs.python.org/3/library/weakref.html 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"