Jestem nowy w Pythonie i uderzyłem w ścianę. Wykonałem kilka samouczków, ale nie mogę ominąć błędu:
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'
Przejrzałem kilka samouczków, ale wydaje mi się, że nic nie różni się od mojego kodu. Jedyne, co mogę wymyślić, to że Python 3.3 wymaga innej składni.
główny scipt:
# test script
from lib.pump import Pump
print ("THIS IS A TEST OF PYTHON") # this prints
p = Pump.getPumps()
print (p)
Klasa pompy:
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
Jeśli dobrze rozumiem, „self” jest automatycznie przekazywane konstruktorowi i metodom. Co ja tu robię źle?
Korzystam z systemu Windows 8 z python 3.3.2