相关疑难解决方法(0)

TypeError:缺少1个必需的位置参数:'self'

我是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'
Run Code Online (Sandbox Code Playgroud)

我检查了几个教程,但似乎与我的代码没有任何不同.我唯一能想到的是python 3.3需要不同的语法.

主要内容:

# test script

from lib.pump import Pump

print ("THIS IS A TEST OF PYTHON") # this prints

p = Pump.getPumps()

print (p)
Run Code Online (Sandbox Code Playgroud)

泵类:

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
Run Code Online (Sandbox Code Playgroud)

如果我理解正确,"self"会自动传递给构造函数和方法.我在这做错了什么?

我使用的是Windows 8和python …

python python-3.x

168
推荐指数
6
解决办法
58万
查看次数

标签 统计

python ×1

python-3.x ×1