我试图用sqlite3和python通过数据库获取单词的数据,但是当我试图调用read \u from \u db函数时,出现了这个错误\u init \uuu()缺少1个必需的位置参数:“receiver”。我似乎找不到发生了什么
这是密码
conn = sqlite3.connect('yeet1.db')
cursor = conn.cursor()
class Ui_WordWindow(object):
def __init__(self, receiver): #Inherit user-input word from another window
self.receiver = receiver
print(self.receiver) #Checking if it worked correctly
def read_From_db(self): #Read and print out data of user-input word
cursor.execute(('SELECT * FROM mytable WHERE Meaning = ?', self.receiver))
data = cursor.fetchall()
print(data)
window2 = Ui_WordWindow()
window2.read_From_db()
cursor.close()
conn.close
声明类
__init__
的Ui_WordWindow
方法,如下所示:它有一个参数接收器。得到的错误表明,在构造
Ui_WordWindow
时,应该只提供一个参数,并且该参数应该是receiver的值。你知道吗即这条线:
事实上应该是:
其中receiver是receiver的有效值。你知道吗
接收方对象=“某个值”
你需要温习一下面向对象的方法。 尝试从以下内容阅读:python object oriented
相关问题 更多 >
编程相关推荐