The following code throws the UnboundLocalError:
def fetch_results(conn, sql, **bind_params):
"""
Immediately fetches the SQL results into memory
Trades memory for the ability to immediately execute another query
"""
global _log_func
try:
cur = conn.cursor()
if _log_func:
_log_func(cur, sql, bind_params)
cur.execute(sql, bind_params)
return cur.fetchall()
finally:
cur.close()
The error:
line 75, in fetch_results
cur.close()
UnboundLocalError: local variable 'cur' referenced before assignment
I am not sure why. Could anybody point me to the right direction?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…