Threading.function TypeError – takes x positional argument but y were given is an error which occurs when you provide a string for args instead of a tuple.
Today I try to explain why this error takes place and how to solve it, I will also add other solutions that could solve the error if possible.
Exploring the Threading.function TypeError – takes x positional argument but y were given
This is an error which occurs when you provide a string for args instead of a tuple.
Do not mix between errors. Make sure the error message looks like the error message bellow after double checking.
# TypeError: startSuggestworker() takes 1 positional argument but y were given #
Bellow is a number of tested solutions that I have tried and worked for me.
The method that solved my problem : give args a tuple instead of giving it a string
The error suggests that startSuggestworker() was given the wrong argument. If you do something like this in your code.
# var = "some string" n = threading.Thread(target=startSuggestworker, args = (var)) #
Then, you are going to get the error, there is no escape. You are giving args a string instead of a tuple.
By the way, it does not have to be var = “some string”. It could be an input which is usually a string etc. …
The solution is to add a comma “,” at the end of the argument provided to args.
# var = "some string" n = threading.Thread(target=startSuggestworker, args = (var,)) #
Now, that we have provided args with a tuple instead of providing it with a string the error will disappear on the next run.
I hope this method has fixed your problem for good, thank you for reading this blog post.
Summing-up :
That is it guys, we arrived at the end of this article, I did my best to help you solve the error : Threading.function TypeError takes x positional argument but y were given , I wish you good luck with your Python projects.
Thank you for reading, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/