Python에서 클래스 인스턴스를 사용하는 데 문제가 있습니다. Ive는 cx_Oracle 패키지에서 연결 클래스를 상속받은 ora 클래스를 새로 만들었습니다. 나는 너와 내가 정보를 받아 봐이 코드를 실행하려고하면Python의 클래스 인스턴스
MYQUERY에서 파일 "pyt.py", 라인 (12), ora.myConnect.cursor() AttributeError : 'NoneType'개체가 어떤 속성 '커서'
이 없습니다그래서 파이썬은 ora.myConnect에서 인스턴스에 대한 참조가 저장되어 있음을 인식합니다. t know what can be reason of this error and what it
코드에 문제가 있습니다.
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/[email protected]:port/sid'
connection = ora(connstr)
connection.myquery()
connection.close()
편집
나는 t 인스턴스에 액세스 할 수 ve tried to replace ora to self but still Python don
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()
오류 : self.myConnect.cursor() AttributeError : 'NoneType'개체가 어떤 속성 '커서'
이 없습니다EDIT2 이 코드는 나를 위해 OOP없이 작동합니다. self.myConnect sholud refere 후부는 객체 인스턴스하고 당신이 self
을 원하는처럼이 객체 메소드 커서()
import cx_oracle
connstr = 'user/[email protected]: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)'이 이상합니다. '__init__' 메쏘드가 커서를 리턴 할 것 같지는 않습니다. 연장하는 수업이 어떻게 작동해야하는지 이해하셨습니까? – beerbajay
[여기에있는 문서] (http://cx-oracle.sourceforge.net/html/module.html#cx_Oracle.connect)에 기반하여 나는 당신이 한 것처럼'connect'를 실제로 확장한다고 말하지 않을 것입니다. 대신'__init__'에서'cx_Oracle.connect()'를 호출하고 연결을'self.myConnect'로 저장하십시오. 연결 = cx_oracle.connect (connstr) 커서 = 연결 : – beerbajay
self.myConnect이 코드는 수입 cx_Oracle과 connstr = '포트/SID를 사용자 /의 passwd @ 호스트를'작동 OOP하지 않고, 예를 들어, 인스턴스를 객체에 을 참조를 반환 sholud. 커서() 커서.execute ("SELECT * FROM table") cursor.close() connection.close() – browarq