我遇到了一些问题,每当我调用我的一个类方法时,它要求我专门发送包含类的调用,我希望它已经知道它自己。我确定这是用户错误,但无法追踪。
我已经引用了python - self - 必需的位置参数,但我想我已经涵盖了。
class SpeechEngine():
def __init__(self):
self.conn = sqlite3.connect('../twbot.db')
self.c = self.conn.cursor()
@staticmethod
def choose(choice):
num_choices = len(choice)
selection = random.randrange(0, num_choices)
return selection
def initial_contact_msg(self, userId, screenName):
hello = self.c.execute("SELECT text, id FROM speechConstructs WHERE type='salutation'").fetchall()
tagline = self.c.execute("SELECT text, id FROM speechConstructs WHERE type='tagline'").fetchall()
c1 = self.choose(hello)
c2 = self.choose(tagline)
msg_string = str(hello[c1][0]) + ' @' + screenName + ' ' + tagline[c2][0]
# print(msg_string) # For Testing Only
# print(hello[c1][1]) # For Testing Only
return msg_string
然后我希望打电话
SpeechEngine.initial_contact_msg(0, 'somename')
但这会返回以下内容
missing 1 required positional argument: 'self'
好像我隐含地这样做
SpeechEngine.initial_contact_msg(SpeechEngine, 0, 'somename')
它不问任何问题就返回预期的结果。我还应该指出,当我将其分配如下时也会发生同样的情况。
test = SpeechEngine
test.initial_contact_msg(0, 'somename')
qq_花开花谢_0
相关分类