del behavior

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

On Wed, Jan 7, 2009 at 11:55 AM, Eric Snow <esnow at> wrote:
> On Jan 7, 12:48 pm, "Chris Rebert" <c... at> wrote:
>> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow <es... at> wrote:
>> > I was reading in the documentation about __del__ and have a couple of
>> > questions.  Here is what I was looking at:
>> >
>> > 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...
> 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.


Follow the path of the Iguana...

More information about the Python-list mailing list