1
import MySQLdb
import sys
from libdesklets.controls import Control
from IDBConnection import IDBConnection
class DBConnection(Control, IDBConnection):
host = 'xxxx'
user = 'xxxx'
passwd = 'xxxx'
db = 'xxxx'
def __init__(self):
Control.__init__(self)
pass
def __get_dbconnection(self):
db = MySQLdb.connect(self.host, self.user, self.passwd, self.db)
return db
def __insert(self):
db = self.__get_dbconnection()
cursor = db.cursor()
cursor.execute("INSERT INTO Usernotes (UID, NID, Inhalt) VALUES (3, 1, 'text');")
cursor.close()
db.close()
def __select(self):
db = self.__get_dbconnection()
cursor = db.cursor()
cursor.execute("SELECT Inhalt FROM Usernotes WHERE UID = 1 AND NID = 1;")
cursor.close()
db.close()
def __update(self):
db = self.__get_dbconnection()
cursor = db.cursor()
cursor.execute("UPDATE Usernotes SET Inhalt = 'inserttest' WHERE UID = 1 AND NID = 2;")
cursor.close()
db.close()
insert = property(__insert, doc="insert into database")
select = property(__select, doc="select from database")
update = property(__update, doc="update database")
def get_class(): return DBConnection
上面的代碼是一個控制與一個MySQL-數據庫Linux gdesklets(那其中進口和控制進口的IDbConnection是來自)工作。因此,當我們從另一個文件(dbc.insert()/ dbc.select()/ dbc.update())調用屬性時,我們得到錯誤「'NoneType'對象不可調用」。如果我們添加返回類型,我們會得到「'ReturnType'對象不可調用」。函數正在工作,數據庫操作已完成,但顯示文件(調用函數的位置)在異常後崩潰。Python數據庫連接「NoneType」對象不是可調用
希望有人可以幫助我們在這裏。
兩個提示:首先,當詢問關於錯誤的問題時,複製/粘貼整個錯誤消息,其中有許多關於發生錯誤的提示。其次,關於「NoneType」的錯誤通常意味着一個函數在你沒有預期的時候返回'None',開始在那裏查找。 –