I'm trying to implement a subclass and it throws the error:
TypeError: worker() takes 0 positional arguments but 1 was given
class KeyStatisticCollection(DataDownloadUtilities.DataDownloadCollection): def GenerateAddressStrings(self): pass def worker(): pass def DownloadProc(self): pass
The Python rule says positional arguments must appear first, followed by the keyword arguments if we are using it together to call the method. The SyntaxError: positional argument follows keyword argument means we have failed to follow the rules of Python while writing a code.
Positional ArgumentsThe first positional argument always needs to be listed first when the function is called. The second positional argument needs to be listed second and the third positional argument listed third, etc. An example of positional arguments can be seen in Python's complex() function.
Positional arguments are arguments that can be called by their position in the function call. Keyword arguments are arguments that can be called by their name. Required arguments are arguments that must passed to the function. Optional arguments are arguments that can be not passed to the function.
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.
If the method doesn't require self
as an argument, you can use the @staticmethod
decorator to avoid the error:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With