[Tutor] Time to Use a Global Variable?

Rich Shepard rshepard at appl-ecosys.com
Wed Feb 8 23:52:18 CET 2006


   In my wxPython application the UI is run out of class MyFrame. The method
associated with File->Quit is called OnFileQuit. All the code for pysqlite is
in another class called DBinterface, and that has a method closeDB():

   def closeDb(self):
     """
     Closes the database connection explicitly.
     """
     self.cur.close()
     self.con.close()

   OnFileQuit looks like this:

   def OnFileQuit(self, event):
     closeDb()
     fn.close()
     self.Close()

   When I test the application and try to close it, python complains
   File "eikos.py", line 315, in OnFileQuit
     closeDb()
NameError: global name 'closeDb' is not defined

   I've tried changing OnFileQuit to call DBinterface.closeDB(), but that
doesn't work. Obviously I still haven't completely grokked how to refer in
one class to a method defined in another class. Of course, I've not
explicitly created an instance of DBinterface within MyFrame, so that may be
the problem.

   A clue stick is welcome.

Rich

-- 
Richard B. Shepard, Ph.D.               |   Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM)   |  Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com>     Voice: 503-667-4517         Fax: 503-667-8863


More information about the Tutor mailing list