del behavior

Benjamin Kaplan benjamin.kaplan at case.edu
Wed Jan 7 23:25:25 CET 2009


On Wed, Jan 7, 2009 at 2:39 PM, Eric Snow <esnow at verio.net> wrote:

> I was reading in the documentation about __del__ and have a couple of
> questions.  Here is what I was looking at:
>
> http://docs.python.org/reference/datamodel.html#object.__del__
>
> What is globals referring to in the following text from that reference
> page?
>
> "Starting with version 1.5, Python guarantees that globals whose name
> begins with a single underscore are deleted from their module before
> other globals are deleted; if no other references to such globals
> exist, this may help in assuring that imported modules are still
> available at the time when the __del__() method is called."
>
> Thus those with an _ get deleted before everything else.  This is not
> referring to members of my objects is it, such that those members
> starting with _ get deleted first?  I suppose that would delete
> __del__ before it would get called so I assume that is not the case.
> But I want to be sure about that behavior and exactly what globals
> is.  Is globals meaning the contents of "globals" or something else.
> I ask because sometimes some words get used for varied meanings.


Names with a *single* leading underscore are, by convention, "private".
Names with double leading and trailing underscores are for special methods.
The sort-of private methods are the ones that get deleted first, not the
special methods.


>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090107/9d156bff/attachment.html>


More information about the Python-list mailing list