Hacker News new | ask | show | jobs
by Jasper_ 3149 days ago
To be clear about the `del block` thing, the only thing that the `del` keyword does in Python is unbind a name from the local scope. It does not cause an object to be destructed, call `__del__`, or anything else. It's morally equivalent to "block = None", except future references to block will raise a NameError instead of giving you None.

When used at the end of a function, when all locals go out of scope, it is actually doing nothing.

1 comments

Unbinding a name does do one thing which might call `__del__`: It decreases the reference count by 1.
In CPython, yes. But this is an implementation detail.
I learned this with PyPy (or maybe it was Jython?). My usual bad habit for small scripts to depend on open files to close when they went out of scope would suddenly exhausted all file descriptors. Ouch.