Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

TypeError: Missing 1 required positional argument: 'self'

I can't move beyond the mistake:

Traceback (most recent call last):
File "C:\Users\Dom\Desktop\test\", line 7, in <module>
p = Pump.getPumps()
TypeError: getPumps() missing 1 required positional argument: 'self'

I examined several tutorials but there doesn't seem to be anything different from my code. the sole thing I can consider is that python 3.3 requires a special syntax.
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
pass # dummy code

p = Pump.getPumps()


If I understand correctly, self is passed to the constructor and methods automatically. What am I doing wrong here?

2 Answers

You need to instantiate a class instance here.


p = Pump()

Small example -

>>> class TestClass:
def __init__(self):
print("in init")
def testFunc(self):
print("in Test Func")

>>> testInstance = TestClass()
in init
>>> testInstance.testFunc()
in Test Func
You need to initialize it first:

p = Pump().getPumps()

Login / Signup to Answer the Question.