I understand that the __del__
function of a Python class is not treated in the way that many people might expect: as a destructor.
I also understand that there are more 'pythonic' and arguably more elegant ways to tidy up, particularly with use of the with construct.
However, when writing code that may be used by an audience less versed in pythonic ways, when cleanup is important, is there an elegant way I can simply get __del__
to work as a destructor reliably, without interfering with python's natural use of __del__
?
The expectation that __del__
behave as a destructor doesn't seem unreasonable and at the same time is quite common. So I'm simply wondering if there is an elegant way to make it work as per that expectation - disregarding the many debates that can be had over the merits of how pythonic it is.