文章内容

2018/12/31 10:31:30,作 者: 黄兵

get_counter() missing 1 required positional argument: 'self'

今天在编码的时候,出现了如下错误:

 get_counter() missing 1 required positional argument: 'self'

具体代码如下:

主要代码如下:

# test script
from lib.pump import Pump
print ("THIS IS A TEST OF PYTHON") # this prints
p = Pump.getPumps()
print (p)


lib.pump.py代码如下:

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

这段代码来自于:TypeError: Missing 1 required positional argument: 'self'

自己的代码太长,就懒得展示了。


出现问题原因:

未初始化直接引用。


解决方案:

修改代码,具体如下:

p = Pump()
p.getPumps()


参考资料:TypeError: Missing 1 required positional argument: 'self'


黄兵个人博客原创。

转载请注明出处:黄兵个人博客 -  get_counter() missing 1 required positional argument: 'self'

分享到:

发表评论

评论列表