Advice needed on __del__

André Roberge andre.roberge at gmail.com
Tue May 10 11:19:56 EDT 2005


Fredrik Lundh wrote:
> André Roberge wrote:
>>If I need to have the user call Evil.destroy() as Evil
>>is getting out of scope, it would miss the whole point
>>of teaching about the natural way scope and namespace
>>work.
> 
> 
> well, if you insist on using finalizers to keep track of what's in the current
> scope, I'd say that you are missing the point about how scopes and name-
> spaces work...
> 
I don't think I do, but I think I didn't explain things well enough.
1. The user creates an object, within a "local" scope.  When he does 
that, I update a list of images in a "global" scope.  I then use that 
list of images to decide what to display on the screen.

The user is unaware of the connection I am making behind the scene.
> 
[Snip]
> 
> the correct solution is to inspect the current namespace every time you
> refresh the screen, and make sure the screen contents matches what's
> in the namespace.

To do that, I would need to put a "link", in the "global" scope between 
the object created by the user, and the user. However, in doing so
(if I am not missing the point about how scopes and namespaces work...)
the object created by the user would always have a reference in the 
global scope ... and thus would never disappear from the namespace.

I understand that, if the "link" is a "weak reference", then it might 
disappear when the object goes out of scope.  Is that what you mean I 
should do?

André
> </F> 





More information about the Python-list mailing list