title: Why am I getting "NameError: global name 'open' is not defined" in __del__?
body: <p>I'm getting a NameError in the __del__ function of a class. I do not understand why 'open' is not accessible inside the function __del__. I am using Python 3.4.0</p>
  
  <p>Python Code:</p>
  
  <pre><code>class Contoller:
  
      ...
  
      def __del__(self):
          store = {}
          ...
          pickle.dump(store, open('data.p', 'wb'))    
  
  class MyWindow(Gtk.Window):
  
      def __init__(self):
          ...
          self.controller = Contoller(self)
          ...
          self.connect("delete-event", self.quit)
          ...
  
      ...
  
      def quit(self, widget, event):
          del self.controller
          Gtk.main_quit()
  </code></pre>
  
  <p>Error Message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "main.py", line 69, in __del__
  NameError: name 'open' is not defined
  </code></pre>