del behavior

Chris Rebert clp2 at rebertia.com
Wed Jan 7 21:05:30 CET 2009


On Wed, Jan 7, 2009 at 11:55 AM, Eric Snow <esnow at verio.net> wrote:
> On Jan 7, 12:48 pm, "Chris Rebert" <c... at rebertia.com> wrote:
>> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow <es... 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?
>>
>> Globals are variables that have toplevel module scope. Basically, any
>> assignments, function definitions, or class definitions with no
>> indentation from the left margin will create a global variable. If you
>> can get at the variable by appending something of the form
>> "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in
>> function, then it's a global.
>>
>> Cheers,
>> Chris
>>
>> --
>> Follow the path of the Iguana...http://rebertia.com
>
> Perfect!  that is kind of what I thought.  Thanks.
>
> So any such in any module every variable in memory that starts with an
> underscore will be deleted before the rest.  Then this does not affect
> the order in which variables are deleted in instances of my classes,
> and thus all my class and instance variables (including methods) are
> available when the __del__ of the class instance is called?

Indeed. The underscore special-casing only applies to modules.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list