class Test(obj):
def __init__(self):
pass
def _is_flag(self):
try:
v_sql="""
Select count(*)
From tablename
"""
push_ctrl_conn=oracle('ETL_TEST')
self.reach_flag=push_ctrl_conn.runsql(v_sql,1)[0][0]
except Exception,e:
self._set_scan_state('22', str(e))
finally:
push_ctrl_conn.close()
def run(self):
self._is_flag()
if name == '__main__':
test_case=Test()
test_case.run()
类似这种格式,然后就报了
UnboundLocalError: local variable 'push_ctrl_conn' referenced before assignment
try語法區塊不一定執行,即
push_ctrl_conn
不一定被賦值。很常見的錯誤,一般可以在try語法前先賦值。像這種連線的需求,一般用上下文管理器功能,我猜oracle函式庫的實例也是支援的。