我有很多数据库查询,我想用一些方法来避免重复我的代码。我想调用其他已定义方法中的方法,但它不起作用
我得到了这样的错误:
class Main:
File "d.py", line 20, in Main
for word in getUserWords("SELECT users.mail, field_data_field_what_word_are_you_looking_.field_what_word_are_you_looking__value, users.uid FROM users INNER JOIN field_data_field_what_word_are_you_looking_ ON users.uid = field_data_field_what_word_are_you_looking_.entity_id"):
TypeError: getUserWords() takes exactly 2 arguments (1 given)
我的代码
^{pr2}$
更简单的例子:
回答您问题的主要要点:
如果你有一个类函数,它有一个按惯例self的第一个参数。如果在实例上调用该类函数(如酒吧功能2)自我是内隐的。如果从类内部调用该类函数(就像function1调用function2时一样),则需要执行以下操作self.functionname,它再次隐式传递自变量。在
第一点:实例化类并在实例上调用
getUserWords()
:第二点:
^{2}$Main
的实现有缺陷。在代码的固定版本可能如下所示:
相关问题 更多 >
编程相关推荐