[Tutor] The case of the missing close

Robert, Andrew ARobert at MFS.com
Tue Nov 30 17:05:57 CET 2004

Hi everyone,

I am trying to create a generic db_utils.py module that I will then
generically import into programs as needed.

The first function I am trying to implement iis to generically open an
Oracle database connection based on passed database/authentication

So far, I have been able to:

- import the custom module db_utils
- pass the parameters function dbopen in the custom module
- open the connection to the requested database
- pass back the cursor object to the calling program for later

The problem is in closing the connection.

No matter what I try,  I receive an error stating that the name is not

I receive an error such as:

Traceback (most recent call last):
  File "M:\My
Documents\python_code\oracle\maestrodev_oracle_connector.py", line 55,
in ?
AttributeError: 'module' object has no attribute 'close'

Does anyone have any ideas on how to properly close the connection?

The db_utils module code is a rather short

def dbopen(db,uname,passwd):
    # Import required system modules needed specifically for function
    import cx_Oracle

    # Connect to remote database
    connection = cx_Oracle.connect(dsn=db,user=uname,password=passwd)
    # Return cursor object to calling program

The code that calls the db_utils module is

# File name: maestrodev_oracle_connector.py
# Author: Andrew Robert
# Date: 11/26/04
# Modification History
# Version          Programmer                   Description
# 1.0               AAR                          Creation
# 1.1               AAR                 Shift database opens to called
# 1.2               AAR                 Fixed database link close - now
# Note on modules
# The imported db_utils module was designed by AAR to make standard
# routines available to all python programs as callable functions.
# Called functions are prefaced with the module name and then the
# within the module.

import sys,db_utils

# Make connection to Oracle development database and assign to object

print 'Establishing connection to remote database\n'
cursobj = db_utils.dbopen('test_d','FOO','foo')

# Formulate sample querry
cursobj.execute('SELECT userid, name, role, desk_phone, pager FROM

# Extract querry results 

for row in results:
    print row

# Break connection to Oracle development database
print '\n\n\nDisconnecting from remote database'


raw_input("\n\n\t\tPress Enter To Continue")

Any help you can provide on this would be greatly appreciated.

Thank you,
Andrew Robert
Systems Architect
Information Technology 
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  arobert at mfs.com
Linux User Number: #201204

"MFS Relay Service" made the following
 annotations on 11/30/2004 11:11:35 AM
This email communication and any attachments may contain proprietary, confidential, or privileged information.  If you are not the intended recipient, you are hereby notified that you have received this email in error and that any review, disclosure, dissemination, distribution or copying of it or its contents is prohibited.  The sender does not waive confidentiality or any privilege by mistransmission.  If you have received this email in error, please notify the sender immediately, delete this email, and destroy all copies and any attachments.

More information about the Tutor mailing list