scope question

Choco java at dejazzd.com
Thu Nov 15 10:21:48 EST 2001


I am re-working a program to abstract some elements of a set of cgi's into 
a shared library.  One thing I'm looking to abstract is the database 
connection code.  To do so, I've created a connect() method and a close() 
method.  The connect() method returns a cursor which the cgi then uses to 
execute a series of sql statements.  To close out the cursor and the 
database connection the cursor is passed to the close method.  How do I get 
this to work?  I find that I cannot simply do this:

def close(cursor):
        cursor.close()
        db.close()

This fails with a NameError: global name 'db' is not defined.

I'm searching for the solution to this at the moment, but thought I'd post 
here to see if anyone had any tips.

Thanks!

Glenn





More information about the Python-list mailing list