Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > del behavior

Reply
Thread Tools

del behavior

 
 
Eric Snow
Guest
Posts: n/a
 
      01-07-2009
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/dat...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.
 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      01-07-2009
On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow <> 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/dat...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
 
Reply With Quote
 
 
 
 
Eric Snow
Guest
Posts: n/a
 
      01-07-2009
On Jan 7, 12:48*pm, "Chris Rebert" <c...@rebertia.com> wrote:
> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow <es...@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/dat...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?

-eric
 
Reply With Quote
 
Eric Snow
Guest
Posts: n/a
 
      01-07-2009
On Jan 7, 12:55*pm, Eric Snow <es...@verio.net> wrote:
> On Jan 7, 12:48*pm, "Chris Rebert" <c...@rebertia.com> wrote:
>
>
>
> > On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow <es...@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/dat...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?
>
> -eric


Typo.

Perfect! that is kind of what I thought. Thanks.

So in any module every such 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?

-eric
 
Reply With Quote
 
Chris Rebert
Guest
Posts: n/a
 
      01-07-2009
On Wed, Jan 7, 2009 at 11:55 AM, Eric Snow <> wrote:
> On Jan 7, 12:48 pm, "Chris Rebert" <c...@rebertia.com> wrote:
>> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow <es...@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/dat...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
 
Reply With Quote
 
MRAB
Guest
Posts: n/a
 
      01-07-2009
Chris Rebert wrote:
> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow <> 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/dat...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.
>

Actually, the amount of indentation doesn't matter. What matters is
whether it's within a 'def' or 'class' statement or not.
 
Reply With Quote
 
Chris Rebert
Guest
Posts: n/a
 
      01-07-2009
On Wed, Jan 7, 2009 at 12:05 PM, MRAB <> wrote:
> Chris Rebert wrote:
>>
>> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow <> 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/dat...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.
>>

> Actually, the amount of indentation doesn't matter. What matters is whether
> it's within a 'def' or 'class' statement or not.


Yes, but those do require you *to indent* (though so do while & if for
that matter); I just couldn't seem to come up with a better
description of the rule at the time.
But you are correct and yours is a much better description of the rule.

Cheers,
Chris

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
del behavior 2 Eric Snow Python 9 01-08-2009 06:21 PM
Interview with Ctrl-Alt-Del Writer Tim Buckley @ ThinkComputers.org Silverstrand Front Page News 0 03-20-2006 02:49 AM
tagging code like del.icio.us, flickr pizarropablo@gmail.com ASP .Net 0 11-04-2005 12:17 PM
Remote Assistance CTRL+ALT+DEL =?Utf-8?B?U3Rldm8=?= MCSE 6 08-20-2005 01:47 PM
undefined behavior or not undefined behavior? That is the question Mantorok Redgormor C Programming 70 02-17-2004 02:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57