Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 
like image 364
StatsViaCsh Avatar asked Sep 19 '13 01:09

StatsViaCsh


People also ask

What is positional argument error in Python?

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.

How do you use positional arguments in Python?

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.

What are positional arguments?

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.


2 Answers

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.

like image 88
Atra Azami Avatar answered Oct 02 '22 23:10

Atra Azami


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

like image 38
Leila Hadj-Chikh Avatar answered Oct 02 '22 23:10

Leila Hadj-Chikh