title: How do I correctly clean up a Python object?
body: <pre><code>class Package:
      def __init__(self):
          self.files = []
  
      # ...
  
      def __del__(self):
          for file in self.files:
              os.unlink(file)
  </code></pre>
  
  <p><code>__del__(self)</code> above fails with an AttributeError exception.  I understand <a href="http://docs.python.org/reference/datamodel.html#customization" rel="noreferrer">Python doesn't guarantee</a> the existence of "global variables" (member data in this context?) when <code>__del__()</code> is invoked.  If that is the case and this is the reason for the exception, how do I make sure the object destructs properly?</p>