I have problem with using class instance in Python. Ive created a new class ora which inherit connect class from cx_Oracle package. When I try tu run this code I recive information
File "pyt.py", line 12, in myquery ora.myConnect.cursor() AttributeError: 'NoneType' object has no attribute 'cursor'
So Python cannote recognize that in ora.myConnect is stored reference to instance.
I dont know what can be reason of this error and what its wrong with code.
from cx_Oracle import connect
class ora(connect):
myConnect = None
def __init__(self,connstr):
ora.myConnect = connect.__init__(self,connstr)
def myquery(self):
ora.myConnect.cursor()
ora.myConnect.cursor.execute("SELECT * FROM table")
ora.myConnect.cursor.close()
connstr = 'user/passwd@host:port/sid'
connection = ora(connstr)
connection.myquery()
connection.close()
EDIT
Ive tried to replace ora to self but still Python dont have access to instance
from cx_Oracle import connect
class ora(connect):
myConnect = None
def __init__(self,connstr):
self.myConnect = connect.__init__(self,connstr)
def myquery(self):
self.myConnect.cursor()
self.myConnect.cursor.execute("SELECT * FROM table")
self.myConnect.cursor.close()
Error: self.myConnect.cursor() AttributeError: 'NoneType' object has no attribute 'cursor'
EDIT2 This code works without OOP, for me self.myConnect sholud reference to object instance and this object should contain method cursor()
import cx_oracle
connstr = 'user/passwd@host:port/sid'
connection = cx_oracle.connect(connstr)
cursor = connection.cursor()
cursor.execute("SELECT * FROM table")
cursor.close()
connection.close()
self.myConnect = connect.__init__(self,connstr)is odd. It seems unlikely that the__init__method should return a cursor. Are you sure you understand how the class you're extending is supposed to work?connectas you have done. Instead, just callcx_Oracle.connect()from your__init__and save the connection asself.myConnect.