简体   繁体   English

Python - TypeError: generateID() 需要 3 个位置 arguments 但给出了 4 个

[英]Python - TypeError: generateID() takes 3 positional arguments but 4 were given

My script contains 4 classes and 1 interface.我的脚本包含 4 个类和 1 个接口。 I have a method generateID which generate an ID according to outputmode , a mode ( modeCB ) and a dataframe ( data_h_f ).我有一个方法generateID ,它根据outputmode 、一个模式( modeCB )和一个 dataframe ( data_h_f )生成一个 ID。 When I execute my class I have this error:当我执行我的 class 我有这个错误:

TypeError: generateID() takes 3 positional arguments but 4 were given TypeError: generateID() 需要 3 个位置 arguments 但给出了 4 个

I'm beginner in python especially objected oriented programming, I don't know if the design of my script is good.我是 python 尤其是面向对象编程的初学者,我不知道我的脚本设计好不好。 I have 3 arguments for my method generateID() and 3 parameters everywere.我有 3 个 arguments 用于我的方法generateID()和 3 个参数。

class OutputMode(object):
    def __init__(self,name,startTime,intervalSeconds,timezone):
    ...

class IDCalculation_I:
    def generateID(outputMode,modeCB,data_h_df):
        pass

class IDCase1(IDCalculation_I):
    def generateID(outputMode,modeCB,data_h_df):
    ...

class Fingerprinter(object):
    def __init__(self,outputMode,modeCB=CONST_MODE_CONT):
        self._modeCB     = modeCB
        self._outputMode = outputMode

    def generateID(outputMode,modeCB,data_h_df):
        pass

    def run(self):
        return self.generateID(outputMode,modeCB,data_h_df)

def main():
    outputMode = OutputMode('EEA','06:00',8*3600,pytz.timezone('Europe/Paris'))
    f1 = Fingerprinter(outputMode, CONST_MODE_CONT)
    t = f1.generateID(outputMode,CONST_MODE_CONT,data_h_df)

if __name__ == '__main__':
    main()
class IDCalculation_I:
    def generateID(self,outputMode,modeCB,data_h_df):
        pass

class IDCase1(IDCalculation_I):
    def generateID(self, outputMode,modeCB,data_h_df):
    ...

class Fingerprinter(object):
    def __init__(self,outputMode,modeCB=CONST_MODE_CONT):
        self._modeCB     = modeCB
        self._outputMode = outputMode

    def generateID(self,outputMode,modeCB,data_h_df):
        pass

    def run(self):
        return self.generateID(outputMode,modeCB,data_h_df)

You forgot to add self .您忘记添加self Or use @staticmethod decorator if you don't want to add self .如果您不想添加self ,或者使用@staticmethod装饰器。

class IDCalculation_I:
    @staticmethod
    def generateID(outputMode,modeCB,data_h_df):
        pass

class IDCase1(IDCalculation_I):
    @staticmethod
    def generateID(outputMode,modeCB,data_h_df):
    ...

class Fingerprinter(object):
    def __init__(self,outputMode,modeCB=CONST_MODE_CONT):
        self._modeCB     = modeCB
        self._outputMode = outputMode

    @staticmethod
    def generateID(outputMode,modeCB,data_h_df):
        pass

    def run(self):
        return self.generateID(outputMode,modeCB,data_h_df)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python TypeError:接受 4 个位置参数,但给出了 5 个 - Python TypeError: takes 4 positional arguments but 5 were given python super:TypeError:__init __()接受2个位置参数,但给出了3个 - python super :TypeError: __init__() takes 2 positional arguments but 3 were given Python/MySQL TypeError:execute() 需要 2 到 4 个位置参数,但给出了 5 个 - Python/MySQL TypeError: execute() takes from 2 to 4 positional arguments but 5 were given TypeError: with_column() 从 3 到 4 个位置 arguments 但给出了 5 个(python) - TypeError: with_column() takes from 3 to 4 positional arguments but 5 were given (python) Python TypeError:衍生物_circ()接受2个位置参数,但给出了6个 - Python TypeError: derivatives_circ() takes 2 positional arguments but 6 were given TypeError:__init __()接受2个位置参数,但是给了3个Python 3? - TypeError: __init__() takes 2 positional arguments but 3 were given Python 3? 类型错误:update() 需要 2 个位置参数,但给出了 3 个:Python - TypeError: update() takes 2 positional arguments but 3 were given : Python TypeError:create()接受2个位置参数,但给出了4个 - TypeError: create() takes 2 positional arguments but 4 were given 类型错误:randint() 需要 3 个位置参数,但给出了 4 个 - TypeError: randint() takes 3 positional arguments but 4 were given TypeError:deriv()接受2个位置参数,但给出了4个 - TypeError: deriv() takes 2 positional arguments but 4 were given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM