== Why _del_ has to be a Python builtin A [[posting today http://community.livejournal.com/python_dev/49088.html]] to the LiveJournal [[python_dev community http://community.livejournal.com/python_dev/]] wound up sort of asking why _del_ has to be a Python builtin instead of a method. At first I thought this had a nice simple answer, but the more I thought about it the less obvious it became, and by the time I'd worked out a satisfying answer I'd had to really think about how Python fits together. The short summary is that _del_ needs to be a builtin because Python's object model is based on references and namespaces, and Python doesn't have a way to refer to your current namespaces (they have no explicit name). Unlike in some languages, _del_ does not literally delete objects; instead it removes references to them (which may as a side effect delete the object). In other words, _del_ is not an object manipulation operation, it is a namespace manipulation operation. So the correct translation of '_del d_' to a method call version cannot be '_d.delete()_'; it has to be '*namespace*_.delete("d")_'. But Python provides no magic *namespace* name for you to use for this operation, because _del_ finds it implicitly. (Compound cases give the namespace; '_del d.c_' is explicitly operating on _d_'s namespace and duly translates to _d.__delattr__("c")_.) There are at least three such anonymous Python namespaces: globals, function locals (including closures), and the namespace of a class as it is being built. Of these, only the global namespace is really accessible; the latter two can only be gotten with magic, and even then you can't use ((__delattr__)) on them. _del_ itself does internal interpreter magic to make it all go. (Note that _locals()_ is explicitly not a reference to the function's namespace; it is a dictionary copy of the function's current namespace. This is because functions don't implement their namespaces using Python dictionaries. Even for things that do implement their namespace using a Python _dict_, it's best considered an implementation detail.) === Sidebar: all but deleting yourself While an object cannot literally delete itself in Python, it can try real hard, by scrubbing its __dict__ and changing its __class__ to something that does nothing. (Unfortunately you can't set your __class__ to plain ((object)), as far as I can tell; you'll need to make an actual do-nothing class.)