[Tutor] Time to Use a Global Variable?

Rich Shepard rshepard at appl-ecosys.com
Thu Feb 9 01:20:04 CET 2006


On Wed, 8 Feb 2006, Kent Johnson wrote:

> Evidently closeDb is an instance method of some class you don't show here.
> Does DBinterface create and maintain a single instance of this class? or
> some other code creates an instance?

Kent,

   closeDB() is defined in the class DBinterface. That's the only instance for
the database connection.

> You need to call closeDb on the DBinterface instance, it is not a
> module-level function. You haven't shown enough code for me to know how
> the OnFileQuit method might gain access to the DBinterface instance; how
> do you access other methods for working with the database?

   I tried calling DBinterface.closeDB(), but python tells me that DBinterface
is not defined. And here I thought that I understood scoping and the use of
classes.

   What shall I provide to help clarify the situation? The class DBinterface
is about 300 lines long.

   The method closeDB() is defined in the class DBinterface. What I'm trying
to do is to ensure that the database cursor and connection are closed when
the user exits from the application. Class DBinterface has a __del__ method
to clean up if the user forgets to close the open database, so I'm trying to
learn how to explicitly close it.

Thanks,

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