Can I pass a cursor to a function?
jestes39 at yahoo.com
jestes39 at yahoo.com
Thu Jun 28 09:26:46 EDT 2001
I am trying to figure out whether or not Python will let me pass a
cursor variable to a function so that I don't have to create another
connection instance to Oracle. Here's the chunk of code:
try:
dbc = odbc.odbc(conn_str)
crsr = dbc.cursor()
except:
raise database_error
while 1:
sql = "SELECT DATA, ROWID FROM <TABLE_NAME>;"
crsr.execute(sql)
records = crsr.fetchall()
for record in records:
pid = `record`[2:4]
rowid = `record`[129:-2]
row_flag = 'TRUE'
if row_flag == 'TRUE':
if pid == 'RE':
receipt_flag = 'TRUE'
receipt_mod.receipt(crsr,record)
else:
time.sleep(5)
I set data up so that both if statements evaluate to true, the flag
is set, and the receipt function is invoked. I get this error if I
try to pass dbc or crsr:
Traceback (most recent call last):
File "C:\proc_mgr.py", line 33, in ?
receipt_mod.receipt(crsr,record)
AttributeError: receipt
If I just pass the record variable, things work fine. Is there a way
that I can pass crsr that I am not seeing or can I make it global and
use it in the function that way? Any help or suggestions will be
appreciated. Thanks.
Jason
More information about the Python-list
mailing list