我是python的新手,並且碰到了一堵牆。我跟着幾個教程,但不能讓過去的錯誤:TypeError:缺少1所需的位置參數:'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'
我檢查幾個教程,但似乎沒有要任何東西從我的代碼不同。我能想到的唯一的事情是python 3.3需要不同的語法。
主要素文字:
# test script
from lib.pump import Pump
print ("THIS IS A TEST OF PYTHON") # this prints
p = Pump.getPumps()
print (p)
水泵類:
import pymysql
class Pump:
def __init__(self):
print ("init") # never prints
def getPumps(self):
# Open database connection
# some stuff here that never gets executed because of error
如果我理解正確的 「自我」 被傳遞給構造函數和方法自動。我在這裏做錯了什麼?
我使用Windows 8與Python 3.3.2
ABC不是一個很好的示例名稱,因爲它代表了抽象基類。 –
試過之前但卻錯過了「()」。在python 3.x中是新的嗎? – DominicM
糟糕。沒意識到。修復它。抱歉。 –