Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

10
  • 3
    Reading what you linked, global variables going away doesn't seem to apply here unless you're talking about when you program is exiting, during which I guess according to what you linked it might be POSSIBLE that the os module itself is already gone. Otherwise, I don't think it applies to member variables in a __del__() method. Commented May 14, 2009 at 19:13
  • 3
    The exception is thrown long before my program exits. The AttributeError exception I get is Python saying it doesn't recognize self.files as being an attribute of Package. I may be getting this wrong, but if by "globals" they don't mean variables global to methods (but possibly local to class) then I don't know what causes this exception. Google hints Python reserves the right to clean up member data before __del__(self) is called. Commented May 14, 2009 at 19:19
  • 1
    The code as posted seems to work for me (with Python 2.5). Can you post the actual code that is failing - or a simplified (the simpler the better version that still causes the error? Commented May 14, 2009 at 19:49
  • @ wilhelmtell can you give a more concrete example? In all my tests, the del destructor works perfectly. Commented May 14, 2009 at 20:07
  • 12
    If anyone wants to know: This article elaborates why __del__ should not be used as the counterpart of __init__. (I.e., it is not a "destructor" in the sense that __init__ is a constructor. Commented Feb 22, 2016 at 5:52