I tend to use it whenever I am working on a prototype script, and:
- Use a somewhat common variable (such as
fileCount
), and - Have a large method (20+ lines), and
- Do not use classes or namespaces yet.
In this situation, in order to avoid potential variable clash, I delete the bugger as soon as I am done with it. I know, in a production code I should avoid 1., 2., and 3., but going from a prototype that works to a completely polished class is time consuming. Sometimes I might want to settle for a sub-optimal, quick refactoring job. In that case I find keeping the del
statements handy. Am I developing an unnecessary, bad habit? Is del
totally avoidable? When would it be a good thing?
del mydict[key]
etc – Acknowledgment