TypeError:缺少一个必需的位置参数:‘Self’我对蟒蛇很陌生,撞到了墙上。我遵循了几个教程,但无法克服这个错误:Traceback (most recent call last):
File "C:\Users\Dom\Desktop\test\test.py", line 7, in <module>
p = Pump.getPumps()TypeError: getPumps() missing 1 required positional argument: 'self'我研究了几个教程,但似乎与我的代码没有什么不同。我唯一能想到的是python3.3需要不同的语法。主枕:# test scriptfrom lib.pump import Pumpprint ("THIS IS A TEST OF PYTHON") # this printsp = Pump.getPumps()print (p)泵级:import pymysqlclass Pump:
def __init__(self):
print ("init") # never prints
def getPumps(self):
# Open database connection
# some stuff here that never gets executed because of error如果我正确理解,“Self”将自动传递给构造函数和方法。我在这里做错什么了?我使用Windows 8和python 3.3.2
3 回答
慕沐林林
TA贡献2016条经验 获得超9个赞
p = Pump()p.getPumps()
>>> class TestClass: def __init__(self): print("in init") def testFunc(self): print("in Test Func")>>> testInstance = TestClass()in init>>> testInstance.testFunc()in Test Func
Cats萌萌
TA贡献1805条经验 获得超9个赞
(yes python does compilation internally)
explicitly
class Pump(): //member variable account_holder balance_amount // constructor def __init__(self,ah,bal): | self.account_holder = ah | self.balance_amount = bal def getPumps(self): | print("The details of your account are:"+self.account_number + self.balance_amount) //object = class(*passing values to constructor*) p = Pump("Tahir",12000) p.getPumps()
添加回答
举报
0/150
提交
取消