Python-TypeError:缺少1个必需的位置参数:'self'
发布于 2021-02-02 23:20:17
我是python新手,碰壁了。我遵循了一些教程,但无法克服错误:
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一起使用
关注者
0
被浏览
72
1 个回答