TypeError:worker()获取0个位置参数但给出了1

时间:2022-08-15 23:18:02

I'm trying to implement a subclass and it throws the error:

我正在尝试实现一个子类,它会抛出错误:

TypeError: worker() takes 0 positional arguments but 1 was given

TypeError:worker()获取0个位置参数但给出了1

class KeyStatisticCollection(DataDownloadUtilities.DataDownloadCollection):
    def GenerateAddressStrings(self):
        pass    
    def worker():
        pass
    def DownloadProc(self):
        pass

4 个解决方案

#1


57  

Your worker method needs 'self' as a parameter, since it is a class method and not a function. Adding that should make it work fine.

您的worker方法需要'self'作为参数,因为它是一个类方法而不是函数。添加它应该使它工作正常。

#2


9  

You forgot to add self as a parameter to the function worker() in the class KeyStatisticCollection.

您忘记将self作为参数添加到KeyStatisticCollection类中的函数worker()中。

#3


8  

If the method doesn't require self as an argument, you can use the @staticmethod decorator to avoid the error:

如果方法不需要self作为参数,则可以使用@staticmethod装饰器来避免错误:

class KeyStatisticCollection(DataDownloadUtilities.DataDownloadCollection):

    def GenerateAddressStrings(self):
        pass    

    @staticmethod
    def worker():
        pass

    def DownloadProc(self):
        pass

See https://docs.python.org/3/library/functions.html#staticmethod

请参阅https://docs.python.org/3/library/functions.html#staticmethod

#4


0  

class KeyStatisticCollection(DataDownloadUtilities.DataDownloadCollection):
def GenerateAddressStrings(self):
    pass    
def worker(self):
    pass
def DownloadProc(self):
    pass

#1


57  

Your worker method needs 'self' as a parameter, since it is a class method and not a function. Adding that should make it work fine.

您的worker方法需要'self'作为参数,因为它是一个类方法而不是函数。添加它应该使它工作正常。

#2


9  

You forgot to add self as a parameter to the function worker() in the class KeyStatisticCollection.

您忘记将self作为参数添加到KeyStatisticCollection类中的函数worker()中。

#3


8  

If the method doesn't require self as an argument, you can use the @staticmethod decorator to avoid the error:

如果方法不需要self作为参数,则可以使用@staticmethod装饰器来避免错误:

class KeyStatisticCollection(DataDownloadUtilities.DataDownloadCollection):

    def GenerateAddressStrings(self):
        pass    

    @staticmethod
    def worker():
        pass

    def DownloadProc(self):
        pass

See https://docs.python.org/3/library/functions.html#staticmethod

请参阅https://docs.python.org/3/library/functions.html#staticmethod

#4


0  

class KeyStatisticCollection(DataDownloadUtilities.DataDownloadCollection):
def GenerateAddressStrings(self):
    pass    
def worker(self):
    pass
def DownloadProc(self):
    pass